c# - 在 Winforms 中使用 Graph# 的示例

标签 c# winforms graph

谁能告诉我如何使用Graph#的例子 通过ElementHostwinforms 应用程序 (c#) 中。

特别是加载 *.gml - 文件并显示图形控件。

感谢任何帮助

最佳答案

基本思想是创建一个 WPF 用户控件,它封装了一个 Graph # canvas。此用户控件是您随后将在 ElementHost 中显示的内容。

我整理了一个小型示例应用程序,它基本上通过将 GraphSharp.Sample.TestCompoundLayout 窗口公开为用户控件来演示这一点。

http://cl.ly/0w350230200g0w0o2R2N

我还添加了从 GML 文件加载,基本上可以归结为这个函数:

        var graph = new CompoundGraph<object, IEdge<object>>();

        try
        {
            //open the file of the graph
            var reader = XmlReader.Create(fileName);

            //create the serializer
            var serializer = new GraphMLDeserializer<object, IEdge<object>, CompoundGraph<object, IEdge<object>>>();


            //deserialize the graph
            serializer.Deserialize(reader, graph,
                                   id => id, (source, target, id) => new Edge<object>(source, target)
                );

        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex);
        }
        layout.Graph = graph;
        layout.UpdateLayout();

关于c# - 在 Winforms 中使用 Graph# 的示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6377347/

相关文章:

c# - Log4net 未登录 Azure Web 应用程序

winforms - 我可以在 Visual Studio 上使用 LinkLabel 链接到 Windows 窗体吗?

python - networkx 中边缘列表的自定义输出

c# - C++ 文件输入输出错误?

c# - 在命令行针对 .vdproj 运行 devenv 不会产生 MSI

c# - UWP 使用 JSON 数据创建列表

language-agnostic - 确定图中给定路径列表的边权重

c# - 将完成的项目转换为 DLL

c# - 在两个表单之间传输数据而无需再次创建新实例

algorithm - 检查一个简单的无向图是否是三连通的