public GraphForm(string fileName) { InitializeComponent(); _graph = new Graph(fileName); /* whenever graph changes, rerender and display the graph */ _graph.Changed += delegate(object sender, EventArgs e) { using (Stream stream = _graph.Render("emfplus:gdiplus")) graphControl.Image = new Metafile(stream); }; _graph.Arguments["layout"] = "dot"; }
public GraphForm(string fileName) { InitializeComponent(); /* window title is the filename portion */ Text = Path.GetFileName(fileName); /* associated icon is eventually sourced by the desktop from this executable's embedded Win32 resources */ Icon = Icon.ExtractAssociatedIcon(fileName); _graph = new Graph(fileName); /* whenever graph changes, rerender and display the graph */ _graph.Changed += delegate(object sender, EventArgs e) { RenderGraph(); }; _graph.Arguments["layout"] = "dot"; _watcher = new PathWatcher(fileName); _watcher.SynchronizingObject = this; _watcher.Changed += delegate(object sender, CancelEventArgs eventArgs) { try { /* replace old graph with new and rerender */ Graph newGraph = new Graph(((PathWatcher)sender).Watched); ((IDisposable)_graph).Dispose(); _graph = newGraph; _graph.Arguments["layout"] = "dot"; RenderGraph(); if (Changed != null) Changed(this, EventArgs.Empty); } catch (Win32Exception exception) { /* if another process is holding on to the graph, try opening again later */ if (exception.NativeErrorCode == 32) eventArgs.Cancel = false; } }; _watcher.Start(); /* set up export dialog with initial file and filters from the graph devices */ StringBuilder exportFilter = new StringBuilder(); int filterIndex = 0; for (int deviceIndex = 0; deviceIndex < _devices.Count; ++deviceIndex) { if (deviceIndex > 0) exportFilter.Append("|"); string device = _devices[deviceIndex]; exportFilter.Append(String.Format("{0} (*.{1})|*.{1}", device.ToUpper(), device)); if (filterIndex == 0 && device == "emfplus") filterIndex = deviceIndex; } exportFileDialog.FileName = Path.GetFileNameWithoutExtension(fileName); exportFileDialog.Filter = exportFilter.ToString(); exportFileDialog.FilterIndex = filterIndex + 1; printDocument.DocumentName = Path.GetFileName(fileName); }
public GraphArguments(Graph graph) { _dictionary = new Dictionary <string, string>(); _graph = graph; }