private void zedGraphControl2_MouseMove(object sender, MouseEventArgs e) { PointF mousePt = new PointF(e.X, e.Y); GraphPane myPane = this.zedGraphControl2.GraphPane; string tooltip = string.Empty; // Find the Chart rect that contains the current mouse location ZedGraphControl s = (ZedGraphControl)sender; GraphPane pane = s.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:" + x.ToString("f6") + ",坐标y: " + y.ToString("f6") + ")"; } // this.zedGraphControl1.GraphPane.Title.Text = tooltip; myPane.XAxis.Title.Text = tooltip; this.zedGraphControl2.Refresh(); }
可以自动显示鼠标坐标点!至于自动缩放,我还不会!
{
//zg.GraphPane.CurveList[n]
try
{
zg.GraphPane.CurveList[n].IsVisible = true;
//zg.ZoomOutAll(zg.GraphPane);
zg.RestoreScale(zg.GraphPane);
zg.AxisChange();
zg.Refresh();
}
catch{}
}
{
PointF mousePt = new PointF(e.X, e.Y);
GraphPane myPane = this.zedGraphControl2.GraphPane;
string tooltip = string.Empty; // Find the Chart rect that contains the current mouse location
ZedGraphControl s = (ZedGraphControl)sender;
GraphPane pane = s.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:" + x.ToString("f6") + ",坐标y: " + y.ToString("f6") + ")";
}
// this.zedGraphControl1.GraphPane.Title.Text = tooltip;
myPane.XAxis.Title.Text = tooltip;
this.zedGraphControl2.Refresh(); }