Ejemplo n.º 1
0
 protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
 {
     base.OnMouseDown(e);
     if (!DesignMode)
     {
         var info = this.CalcHitInfo(e.Location);
         if (info.Diagram != null)
         {
             if (e.Button == System.Windows.Forms.MouseButtons.Left && info.InConstantLine)
             {
                 this.targetLine = info.ConstantLine;
             }
             else if (e.Button == System.Windows.Forms.MouseButtons.Right)
             {
                 var pointinfo = (this.Diagram as DevExpress.XtraCharts.XYDiagram2D).PointToDiagram(e.Location);
                 InitPopupMenu();
                 object argument;
                 if (pointinfo.ArgumentScaleType == DevExpress.XtraCharts.ScaleType.Numerical)
                 {
                     argument = pointinfo.NumericalArgument;
                 }
                 else
                 {
                     argument = pointinfo.QualitativeArgument;
                 }
                 popupMenuStaticItem.Caption = string.Format("X:{0} Y:{1:N3}", argument, pointinfo.NumericalValue);
                 this.RightClickPopupMenu.AddItem(popupMenuStaticItem);
                 popupMenuXAddButtonItem.Tag = new object[] { argument, pointinfo.AxisX };
                 this.RightClickPopupMenu.AddItem(popupMenuXAddButtonItem);
                 ShowRightClickPopupMenuEventArgs eventarg;
                 if (info.InConstantLine)
                 {
                     popupMenuEditItem.BeginUpdate();
                     popupMenuEditItem.Caption   = info.ConstantLine.Name + "轴边界线";
                     popupMenuEditItem.Tag       = info.ConstantLine;
                     popupMenuEditItem.EditValue = info.ConstantLine.AxisValue;
                     popupMenuEditItem.EndUpdate();
                     this.RightClickPopupMenu.AddItem(popupMenuEditItem);
                     popupMenuDeleteButtonItem.Tag     = info.ConstantLine;
                     popupMenuDeleteButtonItem.Caption = "删除" + info.ConstantLine.Name + "轴边界线";
                     this.RightClickPopupMenu.AddItem(popupMenuDeleteButtonItem);
                 }
                 eventarg = new ShowRightClickPopupMenuEventArgs(RightClickPopupMenu, info.ConstantLine, true);
                 if (CustomShowRightClickPopupMenu != null)
                 {
                     CustomShowRightClickPopupMenu(RightClickPopupMenu, eventarg);
                 }
                 if (eventarg.Handle)
                 {
                     this.RightClickPopupMenu.ShowPopup(MousePosition);
                 }
             }
         }
         else if (info.Axis != null && (this.Diagram as DevExpress.XtraCharts.XYDiagram2D).GetAllAxesY().Contains(info.Axis))
         {
             if (e.Button == System.Windows.Forms.MouseButtons.Left)
             {
                 this.targetAxis = (info.Axis as DevExpress.XtraCharts.Axis2D);
             }
             else if (e.Button == System.Windows.Forms.MouseButtons.Right)
             {
                 var pointinfo = (this.Diagram as DevExpress.XtraCharts.XYDiagram2D).PointToDiagram(new System.Drawing.Point(this.Width / 2, e.Location.Y));
                 InitPopupMenu();
                 var value = pointinfo.GetAxisValue(info.Axis).NumericalValue;
                 popupMenuStaticItem.Caption = string.Format("X: Y:{0:N3}", value);
                 this.RightClickPopupMenu.AddItem(popupMenuStaticItem);
                 popupMenuYAddButtonItem.Tag = new object[] { value, info.Axis };
                 this.RightClickPopupMenu.AddItem(popupMenuYAddButtonItem);
                 ShowRightClickPopupMenuEventArgs eventarg;
                 eventarg = new ShowRightClickPopupMenuEventArgs(RightClickPopupMenu, info.ConstantLine, true);
                 if (CustomShowRightClickPopupMenu != null)
                 {
                     CustomShowRightClickPopupMenu(RightClickPopupMenu, eventarg);
                 }
                 if (eventarg.Handle)
                 {
                     this.RightClickPopupMenu.ShowPopup(MousePosition);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (!DesignMode)
            {
                var info = this.CalcHitInfo(e.Location);
                if (info.Diagram != null)
                {

                    if (e.Button == System.Windows.Forms.MouseButtons.Left && info.InConstantLine)
                    {
                        this.targetLine = info.ConstantLine;
                    }
                    else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                    {
                        var pointinfo = (this.Diagram as DevExpress.XtraCharts.XYDiagram2D).PointToDiagram(e.Location);
                        InitPopupMenu();
                        object argument;
                        if (pointinfo.ArgumentScaleType == DevExpress.XtraCharts.ScaleType.Numerical)
                            argument = pointinfo.NumericalArgument;
                        else
                            argument = pointinfo.QualitativeArgument;
                        popupMenuStaticItem.Caption = string.Format("X:{0} Y:{1:N3}", argument, pointinfo.NumericalValue);
                        this.RightClickPopupMenu.AddItem(popupMenuStaticItem);
                        popupMenuXAddButtonItem.Tag = new object[] { argument, pointinfo.AxisX };
                        this.RightClickPopupMenu.AddItem(popupMenuXAddButtonItem);
                        ShowRightClickPopupMenuEventArgs eventarg;
                        if (info.InConstantLine)
                        {
                            popupMenuEditItem.BeginUpdate();
                            popupMenuEditItem.Caption = info.ConstantLine.Name + "轴边界线";
                            popupMenuEditItem.Tag = info.ConstantLine;
                            popupMenuEditItem.EditValue = info.ConstantLine.AxisValue;
                            popupMenuEditItem.EndUpdate();
                            this.RightClickPopupMenu.AddItem(popupMenuEditItem);
                            popupMenuDeleteButtonItem.Tag = info.ConstantLine;
                            popupMenuDeleteButtonItem.Caption = "删除" + info.ConstantLine.Name + "轴边界线";
                            this.RightClickPopupMenu.AddItem(popupMenuDeleteButtonItem);

                        }
                        eventarg = new ShowRightClickPopupMenuEventArgs(RightClickPopupMenu, info.ConstantLine, true);
                        if (CustomShowRightClickPopupMenu != null)
                            CustomShowRightClickPopupMenu(RightClickPopupMenu, eventarg);
                        if (eventarg.Handle)
                            this.RightClickPopupMenu.ShowPopup(MousePosition);
                    }
                }
                else if (info.Axis != null && (this.Diagram as DevExpress.XtraCharts.XYDiagram2D).GetAllAxesY().Contains(info.Axis))
                {
                    if (e.Button == System.Windows.Forms.MouseButtons.Left)
                    {
                        this.targetAxis = (info.Axis as DevExpress.XtraCharts.Axis2D);
                    }
                    else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                    {
                        var pointinfo = (this.Diagram as DevExpress.XtraCharts.XYDiagram2D).PointToDiagram(new System.Drawing.Point(this.Width / 2, e.Location.Y));
                        InitPopupMenu();
                        var value = pointinfo.GetAxisValue(info.Axis).NumericalValue;
                        popupMenuStaticItem.Caption = string.Format("X: Y:{0:N3}", value);
                        this.RightClickPopupMenu.AddItem(popupMenuStaticItem);
                        popupMenuYAddButtonItem.Tag = new object[] { value, info.Axis };
                        this.RightClickPopupMenu.AddItem(popupMenuYAddButtonItem);
                        ShowRightClickPopupMenuEventArgs eventarg;
                        eventarg = new ShowRightClickPopupMenuEventArgs(RightClickPopupMenu, info.ConstantLine, true);
                        if (CustomShowRightClickPopupMenu != null)
                            CustomShowRightClickPopupMenu(RightClickPopupMenu, eventarg);
                        if (eventarg.Handle)
                            this.RightClickPopupMenu.ShowPopup(MousePosition);
                    }

                }
            }
        }