コード例 #1
0
        //Revision: JCarpenter 10/06
        /// <summary>
        /// Find the object currently under the mouse cursor, and return its state.
        /// </summary>
        ContextMenuObjectState GetObjectState()
        {
            var objState = ContextMenuObjectState.Background;

            // Determine object state
            var       mousePt = PointToClient(MousePosition);
            int       iPt;
            GraphPane pane;
            object    nearestObj;

            using (var g = CreateGraphics())
                if (MasterPane.FindNearestPaneObject(
                        mousePt,
                        g,
                        out pane,
                        out nearestObj,
                        out iPt))
                {
                    var item = nearestObj as CurveItem;

                    if (item != null && iPt >= 0)
                    {
                        objState = item.IsSelected ? ContextMenuObjectState.ActiveSelection : ContextMenuObjectState.InactiveSelection;
                    }
                }

            return(objState);
        }
コード例 #2
0
        //---------------------------------------------------------------------------

        //---------------------------------------------------------------------------

        #region Non-Public

        //---------------------------------------------------------------------------

        #region Non-Public Methods

        ///--------------------------------------------------------------------------
        /// <summary>
        /// Individual x- and y- zooming. If, during a zoom action, the extention in
        /// one of the directions is less than 10 pixels, the zoom action is only be
        /// done for the direction with the big extension. A line is drawn instead
        /// of the rectangular rubberband.
        /// </summary>
        /// <returns>True, if a line has been drawn, false otherwise.</returns>
        ///--------------------------------------------------------------------------

        /*
         * private bool DrawLineInsteadOfRectangle()
         * {
         * if (!EnableIndividualXYZoom)
         *  return false;
         *
         * Color color = Color.Cyan;
         * int xPad = Math.Abs(_dragStartPt.X - _dragEndPt.X);
         * int yPad = Math.Abs(_dragStartPt.Y - _dragEndPt.Y);
         *
         * if (!_drawCrossline && (xPad > 1 || yPad > 1))
         *  _drawCrossline = true;
         *
         * if (xPad < 10)
         * {
         *  // Draw vertical line.
         *  Point p1 = new Point(_dragStartPt.X, _dragStartPt.Y);
         *  Point p2 = new Point(_dragStartPt.X, _dragEndPt.Y);
         *  ControlPaint.DrawReversibleLine(PointToScreen(p1), PointToScreen(p2), color);
         *  if (_drawCrossline)
         *  {
         *    p1 = new Point(_dragStartPt.X - 10, _dragStartPt.Y);
         *    p2 = new Point(_dragStartPt.X + 10, _dragStartPt.Y);
         *    ControlPaint.DrawReversibleLine(PointToScreen(p1), PointToScreen(p2), color);
         *
         *    p1 = new Point(_dragStartPt.X - 10, _dragEndPt.Y);
         *    p2 = new Point(_dragStartPt.X + 10, _dragEndPt.Y);
         *    ControlPaint.DrawReversibleLine(PointToScreen(p1), PointToScreen(p2), color);
         *  }
         *
         *  _isEnableHZoom = false;
         *  _isEnableVZoom = true;
         *  return true;
         * }
         *
         * if (yPad < 10)
         * {
         *  // Draw horizontal line.
         *  Point p1 = new Point(_dragStartPt.X, _dragStartPt.Y);
         *  Point p2 = new Point(_dragEndPt.X, _dragStartPt.Y);
         *  ControlPaint.DrawReversibleLine(PointToScreen(p1), PointToScreen(p2), color);
         *  if (_drawCrossline)
         *  {
         *    p1 = new Point(_dragStartPt.X, _dragStartPt.Y - 10);
         *    p2 = new Point(_dragStartPt.X, _dragStartPt.Y + 10);
         *    ControlPaint.DrawReversibleLine(PointToScreen(p1), PointToScreen(p2), color);
         *
         *    p1 = new Point(_dragEndPt.X, _dragStartPt.Y - 10);
         *    p2 = new Point(_dragEndPt.X, _dragStartPt.Y + 10);
         *    ControlPaint.DrawReversibleLine(PointToScreen(p1), PointToScreen(p2), color);
         *  }
         *
         *  _isEnableVZoom = false;
         *  _isEnableHZoom = true;
         *  return true;
         * }
         *
         * // Draw rectangle as usual.
         * _drawCrossline = false;
         * _isEnableHZoom = true;
         * _isEnableVZoom = true;
         * return false;
         * }
         */

        ///------------------------------------------------------------------------
        /// <summary>
        /// Handles the Opening event of the ContextMenuStrip control.
        /// It should not pop down when a legend item was clicked.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/>
        /// instance containing the event data.</param>
        ///------------------------------------------------------------------------
        private void ContextMenuStrip_Opening(object sender, CancelEventArgs e)
        {
            var graphPane = this.MasterPane.FindPane(this._menuClickPt);

            using (var g = this.CreateGraphics())
            {
                object nearestObject;
                int    index;
                if (MasterPane.FindNearestPaneObject(_menuClickPt, g, out graphPane, out nearestObject, out index))
                {
                    if (nearestObject is Legend)
                    {
                        e.Cancel = true;
                    }
                }
                else if (MasterPane.Legend.FindPoint(_menuClickPt, MasterPane, MasterPane.CalcScaleFactor(), out index))
                {
                    e.Cancel = true;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// private method for handling MouseMove events to display tooltips over
        /// individual datapoints.
        /// </summary>
        /// <param name="sender">
        /// A reference to the control that has the MouseMove event.
        /// </param>
        /// <param name="e">
        /// A MouseEventArgs object.
        /// </param>
        private void ZedGraphControl_MouseMove(object sender, MouseEventArgs e)
        {
            Point mousePt = new Point(e.X, e.Y);

            SetCursor(mousePt);

            // If the mouse is being dragged,
            // undraw and redraw the rectangle as the mouse moves.
            if (this.isZooming)
            {
                // Hide the previous rectangle by calling the
                // DrawReversibleFrame method with the same parameters.
                ControlPaint.DrawReversibleFrame(this.dragRect,
                                                 this.BackColor, FrameStyle.Dashed);

                // Calculate the endpoint and dimensions for the new
                // rectangle, again using the PointToScreen method.
                Point curPt = ((Control)sender).PointToScreen(mousePt);
                this.dragRect.Width  = curPt.X - this.dragRect.X;
                this.dragRect.Height = curPt.Y - this.dragRect.Y;

                // Draw the new rectangle by calling DrawReversibleFrame
                // again.
                ControlPaint.DrawReversibleFrame(this.dragRect,
                                                 this.BackColor, FrameStyle.Dashed);
            }
            else if (this.isPanning)
            {
                double x1, x2, y1, y2, yy1, yy2;
                PointF endPoint   = new PointF(e.X, e.Y);
                PointF startPoint = ((Control)sender).PointToClient(this.dragRect.Location);

                this.dragPane.ReverseTransform(startPoint, out x1, out y1, out yy1);
                this.dragPane.ReverseTransform(endPoint, out x2, out y2, out yy2);

                this.dragPane.XAxis.Min += x1 - x2;
                this.dragPane.XAxis.Max += x1 - x2;
                this.dragPane.YAxis.Min += y1 - y2;
                this.dragPane.YAxis.Max += y1 - y2;
                Refresh();

                this.dragRect.Location = ((Control)sender).PointToScreen(mousePt);
            }
            else if (isShowPointValues)
            {
                int       iPt;
                GraphPane pane;
                object    nearestObj;

                Graphics g = this.CreateGraphics();

                if (masterPane.FindNearestPaneObject(new PointF(e.X, e.Y),
                                                     g, out pane, out nearestObj, out iPt))
                {
                    if (nearestObj is CurveItem && iPt >= 0)
                    {
                        CurveItem curve = (CurveItem)nearestObj;
                        if (curve is PieItem)
                        {
                            this.pointToolTip.SetToolTip(this,
                                                         ((PieItem)curve).Value.ToString(this.pointValueFormat));
                        }
                        else
                        {
                            PointPair pt = curve.Points[iPt];

                            if (pt.Tag is string)
                            {
                                this.pointToolTip.SetToolTip(this, (string)pt.Tag);
                            }
                            else
                            {
                                string xStr, yStr;

                                if (pane.XAxis.IsDate)
                                {
                                    xStr = XDate.ToString(pt.X, this.pointDateFormat);
                                }
                                else if (pane.XAxis.IsText && pane.XAxis.TextLabels != null &&
                                         iPt >= 0 && iPt < pane.XAxis.TextLabels.Length)
                                {
                                    xStr = pane.XAxis.TextLabels[iPt];
                                }
                                else
                                {
                                    xStr = pt.X.ToString(this.pointValueFormat);
                                }

                                Axis yAxis = curve.IsY2Axis ? (Axis)pane.Y2Axis : (Axis)pane.YAxis;

                                if (yAxis.IsDate)
                                {
                                    yStr = XDate.ToString(pt.Y, this.pointDateFormat);
                                }
                                else if (yAxis.IsText && yAxis.TextLabels != null &&
                                         iPt >= 0 && iPt < yAxis.TextLabels.Length)
                                {
                                    yStr = yAxis.TextLabels[iPt];
                                }
                                else
                                {
                                    yStr = pt.Y.ToString(this.pointValueFormat);
                                }

                                this.pointToolTip.SetToolTip(this, "( " + xStr + ", " + yStr + " )");

                                //this.pointToolTip.SetToolTip( this,
                                //	curve.Points[iPt].ToString( this.pointValueFormat ) );
                            }
                        }

                        this.pointToolTip.Active = true;
                    }
                    else
                    {
                        this.pointToolTip.Active = false;
                    }
                }

                g.Dispose();
            }
        }