当前位置: 移动技术网 > IT编程>开发语言>.net > Winforn中实现ZedGraph自定义添加右键菜单项(附源码下载)

Winforn中实现ZedGraph自定义添加右键菜单项(附源码下载)

2019年08月29日  | 移动技术网IT编程  | 我要评论

beauty4you,刘纾妤,三国城池风暴

场景

winform中实现zedgraph中曲线右键显示为中文:

https://blog.csdn.net/badao_liumang_qizhi/article/details/100115292

在上面实现将zedgraph的右键显示为中文后,再实现自定义菜单的添加。

效果

 

 

源码下载

实现

前面已经将鼠标的右键事件与方法绑定

this.zedgraphcontrol1.contextmenubuilder += mycontextmenubuilder;

 

在方法mycontextmenubuilder中

 

//新建菜单项对象
            toolstripmenuitem item1 = new toolstripmenuitem();
            //设置名字
            item1.name = "line_set";
            //设置显示文本
            item1.text = "霸道流氓";
            //点击事件与方法绑定
            item1.click += mouseenter;
            //菜单项添加到右键菜单
            menustrip.items.add(item1);

 

实现了添加一个右键菜单,将其点击事件与mouseenter方法绑定。

在窗体类下定义事件

 

//mouseeventhandler :表示将处理窗体、控件或其他组件的 mousedown、mouseup 或 mousemove 事件的方法。
        // event关键字代表事件,返回类型为委托;
        public static event eventhandler mouseenter;

 

然后在初始化窗体的位置将事件与自定义方法相绑定。

 

public form1()
        {
            initializecomponent();
            //form1初始化后创建设置控件的方法并将当前zedgraph控件传递
            createpane(zedgraphcontrol1);
            //事件与方法绑定
            mouseenter += new eventhandler(onmouseenter);

        }

 

位置

 

 

完整mycontextmenubuilder方法

 private static void mycontextmenubuilder(zedgraphcontrol control, contextmenustrip menustrip,
                    point mousept, zedgraphcontrol.contextmenuobjectstate objstate)
        {
            //新建菜单项对象
            toolstripmenuitem item1 = new toolstripmenuitem();
            //设置名字
            item1.name = "line_set";
            //设置显示文本
            item1.text = "霸道流氓";
            //点击事件与方法绑定
            item1.click += mouseenter;
            //菜单项添加到右键菜单
            menustrip.items.add(item1);
            //汉化右键菜单
            foreach (toolstripmenuitem item in menustrip.items)
            {
                switch (item.name)
                {
                    case "copied_to_clip":
                        item.text = @"复制到剪贴板";
                        break;
                    case "copy":
                        item.text = @"复制";
                        break;
                    case "page_setup":
                        item.text = @"页面设置...";
                        break;
                    case "print":
                        item.text = @"打印...";
                        break;
                    case "save_as":
                        item.text = @"另存图表...";
                        break;
                    case "set_default":
                        item.text = @"恢复默认大小";
                        break;
                    case "show_val":
                        item.text = @"显示节点数值";
                        break;
                    case "title_def":
                        item.text = @"标题";
                        break;
                    case "undo_all":
                        item.text = @"还原缩放/移动";
                        break;

                    case "unpan":
                        item.text = @"还原移动";
                        break;

                    case "unzoom":
                        item.text = @"还原缩放";
                        break;

                    case "x_title_def":
                        item.text = @"x 轴";
                        break;
                    case "y_title_def":
                        item.text = @"y 轴";
                        break;

                }
            }
        }

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网