日期:2014-05-20  浏览次数:20976 次

zedgraph获取鼠标位置坐标
我用zedgraph画了许多等值线,希望随着鼠标的移动获得横纵坐标(没有画点的位置也希望能取得到),但是怎么都没做到,求指教~!

------解决方案--------------------
或者:
C# code

        private void zedGraphControl1_MouseMove(object sender, MouseEventArgs e)
        {
            // Save the mouse location
            PointF mousePt = new PointF(e.X, e.Y);

            string tooltip = string.Empty;

            // Find the Chart rect that contains the current mouse location
            GraphPane pane = ((ZedGraphControl)sender).MasterPane.FindChartRect(mousePt);

            // If pane is non-null, we have a valid location.  Otherwise, the mouse is not
            // within any chart rect.
            if (pane != null)
            {
                double x, y;
                // Convert the mouse location to X, and Y scale values
                pane.ReverseTransform(mousePt, out x, out y);
                // 获取横纵坐标信息
                tooltip = "(" + x.ToString("f2") + ", " + y.ToString("f2") + ")";
            }

            toolTip1.SetToolTip(zedGraphControl1, tooltip);
        }