当前位置: 移动技术网 > IT编程>开发语言>c# > Winform中设置ZedGraph鼠标悬浮显示举例最近曲线上的点的坐标值和X轴与Y轴的标题

Winform中设置ZedGraph鼠标悬浮显示举例最近曲线上的点的坐标值和X轴与Y轴的标题

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

场景

winform中设置zedgraph鼠标双击获取距离最近曲线上的点的坐标值:

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

现在要实现鼠标悬浮时显示距离最近曲线上的点的横纵坐标和x轴和y轴的标题。

 

 

注:

博客主页:

关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

在包含zedgraph控件的窗体的load方法中执行初始化zedgraph的方法,在初始化的方法中对鼠标悬浮事件重新绑定。

zgc.cursorvalueevent -= zgc_cursorvalueevent;       //显示焦点值事件
zgc.cursorvalueevent += zgc_cursorvalueevent;       //显示焦点值事件

 

然后在显示焦点值事件中

private static string zgc_cursorvalueevent(zedgraphcontrol sender, graphpane pane, point mousept)
        {
            //获取zedgraphcontrol对象
            zedgraphcontrol zgc = sender as zedgraphcontrol;
            if (zgc != null)
            {
                //声明曲线对象
                curveitem nearstcurve;
                int i;
                double y = 0.0;
                string z = string.empty;
                string xtitle = string.empty;
                string yttile = string.empty;
                try
                {
                    //获取距离最近的曲线
                    zgc.graphpane.findnearestpoint(mousept, out nearstcurve, out i);
                    if (nearstcurve != null && nearstcurve.points.count > i && nearstcurve.points[i] != null)
                    {
                        //获取举例最近的点的tag,在生成曲线时使用tag存储的x轴的信息
                        z = nearstcurve.points[i].tag.tostring();
                        //获取当前pane面板的xaxis的标题的文本内容
                        xtitle = zgc.graphpane.xaxis.title.text;
                        //获取当前pane面板的yaxis的标题的文本内容,通过nearstcurve.yaxisindex获取当前举例最近的曲线所对应的y轴的index
                        yttile = zgc.graphpane.yaxislist[nearstcurve.yaxisindex].title.text;
                        y = nearstcurve.points[i].y;
                    }
                }
                catch(exception ex)
                {

                }
                return "x-" + xtitle + ": " + z + "  y-" + yttile +": "+ y.tostring();
            }
            else
            {
                return string.empty;
            }
        } 

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网