Winform中设置ZedGraph鼠标悬浮显示距离最近曲线上的点的坐标值和X轴与Y轴的标题
生活随笔
收集整理的這篇文章主要介紹了
Winform中设置ZedGraph鼠标悬浮显示距离最近曲线上的点的坐标值和X轴与Y轴的标题
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
場(chǎng)景
Winform中設(shè)置ZedGraph鼠標(biāo)雙擊獲取距離最近曲線上的點(diǎn)的坐標(biāo)值:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/102466406
現(xiàn)在要實(shí)現(xiàn)鼠標(biāo)懸浮時(shí)顯示距離最近曲線上的點(diǎn)的橫縱坐標(biāo)和X軸和Y軸的標(biāo)題。
?
注:
博客主頁:
https://blog.csdn.net/badao_liumang_qizhi
關(guān)注公眾號(hào)
霸道的程序猿
獲取編程相關(guān)電子書、教程推送與免費(fèi)下載。
實(shí)現(xiàn)
在包含ZedGraph控件的窗體的load方法中執(zhí)行初始化zedGraph的方法,在初始化的方法中對(duì)鼠標(biāo)懸浮事件重新綁定。
zgc.CursorValueEvent -= zgc_CursorValueEvent;?????? //顯示焦點(diǎn)值事件 zgc.CursorValueEvent += zgc_CursorValueEvent;?????? //顯示焦點(diǎn)值事件然后在顯示焦點(diǎn)值事件中
private static string zgc_CursorValueEvent(ZedGraphControl sender, GraphPane pane, Point mousePt){//獲取ZedGraphControl對(duì)象ZedGraphControl zgc = sender as ZedGraphControl;if (zgc != null){//聲明曲線對(duì)象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){//獲取舉例最近的點(diǎn)的Tag,在生成曲線時(shí)使用Tag存儲(chǔ)的X軸的信息z = nearstCurve.Points[i].Tag.ToString();//獲取當(dāng)前pane面板的XAxis的標(biāo)題的文本內(nèi)容xTitle = zgc.GraphPane.XAxis.Title.Text;//獲取當(dāng)前pane面板的YAxis的標(biāo)題的文本內(nèi)容,通過nearstCurve.YAxisIndex獲取當(dāng)前舉例最近的曲線所對(duì)應(yīng)的Y軸的IndexyTtile = 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;}}?
與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的Winform中设置ZedGraph鼠标悬浮显示距离最近曲线上的点的坐标值和X轴与Y轴的标题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DevExpress的进度条控件Prog
- 下一篇: Winform巧用窗体设计完成弹窗数值绑