/// <summary> /// Action call for the Mouse-Move event. For the x-coordinate /// supplied by the MouseEvent, the unscaled x and y coordinates /// of the plotted function are determined and displayed /// on the control. /// </summary> private void mouseMoved(object sender, MouseEventArgs e) { int Xh, Xc; HTuple Ytup; float Yh, Yc; Xh = e.X; if (PreX == Xh || Xh < originX || Xh > BorderRight || func == null) { return; } PreX = Xh; Xc = (int)Math.Round((Xh - originX) / scaleX); Ytup = func.GetYValueFunct1d(new HTuple(Xc), "zero"); Yc = (float)Ytup[0].D; Yh = panelHeight - (Yc * scaleY); gPanel.DrawImageUnscaled(functionMap, 0, 0); gPanel.DrawLine(penCursor, Xh, 0, Xh, BorderTop); gPanel.DrawLine(penCursor, originX, Yh, BorderRight + margin, Yh); gPanel.DrawString(("X = " + Xc), drawFont, brushCS, panelWidth - margin, 10); gPanel.DrawString(("Y = " + (int)Yc), drawFont, brushCS, panelWidth - margin, 20); gPanel.Flush(); }
/// <summary> /// Action call for the Mouse-Move event. For the x-coordinate /// supplied by the MouseEvent, the unscaled x and y coordinates /// of the plotted function are determined and displayed /// on the control. /// </summary> private void panel_MouseMove(object sender, MouseEventArgs e) { int Xh, Xc; HTuple Ytup; float Yh, Yc; Xh = e.X; if (PreX == Xh || Xh < originX || Xh > BorderRight || func == null) { return; } PreX = Xh; Xc = (int)Math.Round((Xh - originX) / scaleX); Ytup = func.GetYValueFunct1d(new HTuple(Xc), "zero"); Yc = (float)Ytup[0].D; Yh = panelHeight - (Yc * scaleY); BufferedGraphicsContext ctx = BufferedGraphicsManager.Current; BufferedGraphics bg = ctx.Allocate(gPanel, new Rectangle(new Point(0, 0), panel.Size)); Graphics gOfbuff = bg.Graphics; Bitmap toDrawBeffor = new Bitmap(panel.Width, panel.Height); Graphics gOfToDrawBeffor = Graphics.FromImage(toDrawBeffor); // 自定义绘图 gOfToDrawBeffor.DrawLine(Pens.Blue, 0, 0, 1000, 1000); gOfToDrawBeffor.DrawImageUnscaled(functionMap, 0, 0); gOfToDrawBeffor.DrawLine(penCursor, Xh, 0, Xh, BorderTop); gOfToDrawBeffor.DrawLine(penCursor, originX, Yh, BorderRight + margin, Yh); string xStr = string.Format("{0}={1}", XName, Xc); string yStr = string.Format("{0}={1}", YName, (int)Yc); gOfToDrawBeffor.DrawString(xStr, drawFont, brushCS, panelWidth - margin * 4, 10); gOfToDrawBeffor.DrawString(yStr, drawFont, brushCS, panelWidth - margin * 4, 20); //双缓存到panel上 gOfbuff.Clear(panel.BackColor); gOfbuff.DrawImage(toDrawBeffor, 0, 0); bg.Render(); toDrawBeffor.Dispose(); gOfToDrawBeffor.Dispose(); gOfbuff.Dispose(); ctx.Dispose(); bg.Dispose(); }