MSAGL Graph C#

Errataaaaaa 1 Reputation point

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?

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
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

    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  
         viewer.Dock =System.Windows.Forms.DockStyle.Fill;  

    The result:
    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

    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;