FirstCal_Margin = true; }
OnMouseMoveHelp(e.x, e.y); }
protected double_PlotXPosition = 0.0;//捕鼠标在绘图控件上对应的X坐标值 protected double _PlotYPosition = 0.0;// 鼠标在绘图控件上对应的Y坐标值 CWPlotm_Default_Plot=null;绘图图层 Bool IsStart=false;//标识是否开始绘图
protected SnapNearPoint snap = null;//捕捉点类
protected CWCursor m_Default_Cursor = null;//默认鼠标 protectedvoid OnMouseMoveHelp(int x,int y) {
try {
_PlotXPosition=Convert.ToDouble(_widthMap)/ (Convert.ToDouble(m_Default_Plot.XAxis.Maximum)
-Convert.ToDouble(m_Default_Plot.XAxis.Minimum));//计算刻度的像素值 _PlotYPosition=Convert.ToDouble(_heightMap)/ (Convert.ToDouble(m_Default_Plot.YAxis.Maximum)-
Convert.ToDouble(m_Default_Plot.YAxis.Minimum));//用Y轴高度除Y轴坐标起始值差得到Y轴的刻度最小单位长度
_PlotXPosition =Convert.ToDouble(m_Default_Plot.XAxis.Minimum) + ((x - _leftMap) /_PlotXPosition);//反推长度\\刻度确定当前鼠标点对应的Y轴坐标值
_PlotYPosition =Convert.ToDouble(m_Default_Plot.YAxis.Minimum) - ((y - _topMap - _heightMap) /_PlotYPosition); if (!IsStart) {
this.Cursor =System.Windows.Forms.Cursors.SizeAll;
m_Default_Cursor.XPosition =_PlotXPosition;//设置光标样式 m_Default_Cursor.YPosition= _PlotYPosition; } else {
this.Cursor =System.Windows.Forms.Cursors.Arrow; }
if (m_YData != null &&m_XData != null && snap != null) {
snap.BindXData = m_XData; snap.BindYData = m_YData; StartSnap();
m_Default_Cursor.XPosition= MouseCenterFreq_X + _XMove; m_Default_Cursor.YPosition= MouseCenterFreq_Y + _YMove; } }
catch (Exception ex) {
LoggingUtility.ErrorInfo(ex); } }
protected double MouseCenterFreq_X =0.0;//捕捉到的点的X坐标 protected double MouseCenterFreq_Y =0.0;//捕捉到最近点的Y坐标 ///
protected void StartSnap() {
if (snap.BindXData.Count >= 1) {
snap.GetNearPoint(_PlotXPosition, _PlotYPosition, ref MouseCenterFreq_X,ref MouseCenterFreq_Y); if (snap.SelectIndex != -1) {
SelFreqIndex =snap.SelectIndex;
//GetNearPoint(MouseCenterFreq_X, MouseCenterFreq_Y); //激发事件 用在外部调用时候用事件接受捕捉点,可用可不用 } } }
//public delegate voidGetNearPointEventHandle(double x, double y);//捕捉点委托
//public event GetNearPointEventHandleOnGetNearPoint; ///
/// 用来激发捕捉到最近点的事件 ///
/// //protected void GetNearPoint(double x,double y) //{ // if (OnGetNearPoint != null) // { // OnGetNearPoint(x, y); // } // } 附加一张效果图吧:光标定位地区就是捕捉到的点值,左上角显示的是数值。 主要计算偏多,思路很简单。代码也比较多,看起来比较繁琐。。。。
相关推荐: