MSAGL Graph C#

Errataaaaaa 1 Reputation point
2021-03-19T04:38:57.197+00:00

Hello, I am trying to make an app with Winforms. The app uses MSAGL to visualize a graph. Can you visualize this graph in the same form as my app, i.e. not making new form for it? Thanks

Edit: I can insert the graph to the form. But, can you make sure that the graph back color is the same as the one you set before? And how about a fixed layout, i.e. the layout of the MSAGL viewer?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,605 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,657 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,621 Reputation points
    2021-03-19T08:18:13.667+00:00

    Hi RichardRivaldo-2611,
    I made a test via Microsoft.Msagl.GraphViewerGdi you can refer to.

        private void Form1_Load(object sender, EventArgs e)  
        {  
         //create a viewer object  
         Microsoft.Msagl.GraphViewerGdi.GViewer viewer= new Microsoft.Msagl.GraphViewerGdi.GViewer();  
         //create a graph object  
         Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph");  
        //set graph back color  
      //graph.Attr.BackgroundColor = Microsoft.Msagl.Drawing.Color.Gray;  
         //create the graph content  
         graph.AddEdge("A", "B");  
         graph.AddEdge("B", "C");  
         graph.FindNode("A").Attr.FillColor =Microsoft.Msagl.Drawing.Color.Red;  
         graph.FindNode("B").Attr.FillColor =Microsoft.Msagl.Drawing.Color.Green;  
         Microsoft.Msagl.Drawing.Node c =graph.FindNode("C");  
         c.Attr.FillColor =Microsoft.Msagl.Drawing.Color.PaleGreen;  
         c.Attr.Shape =Microsoft.Msagl.Drawing.Shape.Diamond;  
         //bind the graph to the viewer  
         viewer.Graph = graph;  
         //associate the viewer with the form  
         this.SuspendLayout();  
         viewer.Dock =System.Windows.Forms.DockStyle.Fill;  
         this.Controls.Add(viewer);  
         this.ResumeLayout();  
        }  
    

    The result:
    79514-319.png
    More details you can refe to this document.
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Castorix31 83,096 Reputation points
    2021-03-19T08:27:33.607+00:00

    You just add the Viewer with Controls.Add of your Form, like any other control
    And you can change all colors
    For example, I have set the background graph color to Yellow and Viewer "outside" background to Red :

    graph.Attr.BackgroundColor = Microsoft.Msagl.Drawing.Color.Yellow;  
    

    in ScrollGViewer.cs :

    Brush outsideAreaBrush = Brushes.Red;  
    

    79515-msagl.jpg