본문 바로가기

프로그래밍 언어 노트/C#

[C#/Winform] Microsoft Automatic Graph Layout (MSAGL)

https://www.microsoft.com/en-us/research/project/microsoft-automatic-graph-layout/?from=http%3A%2F%2Fresearch.microsoft.com%2Fen-us%2Fprojects%2Fmsagl%2F#!code-samples


뭐 이쁘장하게 그려주는건 아닌데

NeGet에서 간단히 다운받고 사용하기 쉽다.


Microsoft Automatic Graph Layout


using System;
using System.Collections.Generic;
using System.Windows.Forms;
class ViewerSample {
	public static void Main() {
		//create a form
		System.Windows.Forms.Form form = new 
System.Windows.Forms.Form();
		//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");
//create the graph content
		graph.AddEdge("A", "B");
		graph.AddEdge("B", "C");
		graph.AddEdge("A", "C").EdgeAttr.Color = 
Microsoft.Msagl.Drawing.Color.Green;
		graph.FindNode("A").Attr.Fillcolor = 
Microsoft.Msagl.Drawing.Color.Magenta;
		graph.FindNode("B").Attr.Fillcolor = 
Microsoft.Msagl.Drawing.Color.MistyRose;
		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
		form.SuspendLayout();
		viewer.Dock = 
System.Windows.Forms.DockStyle.Fill;
		form.Controls.Add(viewer);
		form.ResumeLayout();
		///show the form
		form.ShowDialog();
	   }
	}


요런식 WinForm 만 올리고 WPF 에서 정식으로 지원안하는지 WPF 코드는 딱히 없는듯

걍 WPF에서 winform 띄우기로 했다.

728x90