private void btOK_Click(object sender, EventArgs e)
        {
            bool inputValid = true;

            //Sanity Check
            if (!ValidateInput(txtXMin))
            {
                inputValid = false;
            }
            if (!ValidateInput(txtXMax))
            {
                inputValid = false;
            }
            if (!ValidateInput(txtYMin))
            {
                inputValid = false;
            }
            if (!ValidateInput(txtYMax))
            {
                inputValid = false;
            }
            if (!inputValid)
            {
                MessageBox.Show("Invalid input values!", this.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Limit Check
            double xStart = Convert.ToDouble(txtXMin.Text);
            double xEnd   = Convert.ToDouble(txtXMax.Text);
            double yStart = Convert.ToDouble(txtYMin.Text);
            double yEnd   = Convert.ToDouble(txtYMax.Text);

            //Perform ZOOM
            double XMin = ptrXAxis.ValueToPixelPosition(xStart);
            double XMax = ptrXAxis.ValueToPixelPosition(xEnd);
            double YMin = ptrYAxis.ValueToPixelPosition(yStart);
            double YMax = ptrYAxis.ValueToPixelPosition(yEnd);

            ptrXAxis.ScaleView.Zoom(xStart, xEnd);
            ptrYAxis.ScaleView.Zoom(yStart, yEnd);

            //Swtich to next axis
            ptrXAxis = (ptrXAxis == ptrChartArea.AxisX) ? ptrChartArea.AxisX2 : ptrChartArea.AxisX;
            ptrYAxis = (ptrYAxis == ptrChartArea.AxisY) ? ptrChartArea.AxisY2 : ptrChartArea.AxisY;
            ptrXAxis.ScaleView.Zoom(ptrXAxis.PixelPositionToValue(XMin), ptrXAxis.PixelPositionToValue(XMax));
            ptrYAxis.ScaleView.Zoom(ptrYAxis.PixelPositionToValue(YMin), ptrYAxis.PixelPositionToValue(YMax));

            DialogResult = DialogResult.OK;
        }
        private void btOK_Click(object sender, EventArgs e)
        {
            bool inputValid = true;

            //Sanity Check
            if (!ValidateInput(txtXMin)) { inputValid = false; }
            if (!ValidateInput(txtXMax)) { inputValid = false; }
            if (!ValidateInput(txtYMin)) { inputValid = false; }
            if (!ValidateInput(txtYMax)) { inputValid = false; }
            if (!inputValid)
            {
                MessageBox.Show("Invalid input values!", this.Text,
                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Limit Check
            double xStart = Convert.ToDouble(txtXMin.Text);
            double xEnd = Convert.ToDouble(txtXMax.Text);
            double yStart = Convert.ToDouble(txtYMin.Text);
            double yEnd = Convert.ToDouble(txtYMax.Text);

            //Perform ZOOM
            double XMin = ptrXAxis.ValueToPixelPosition(xStart);
            double XMax = ptrXAxis.ValueToPixelPosition(xEnd);
            double YMin = ptrYAxis.ValueToPixelPosition(yStart);
            double YMax = ptrYAxis.ValueToPixelPosition(yEnd);

            ptrXAxis.ScaleView.Zoom(xStart, xEnd);
            ptrYAxis.ScaleView.Zoom(yStart, yEnd);

            //Swtich to next axis
            ptrXAxis = (ptrXAxis == ptrChartArea.AxisX) ? ptrChartArea.AxisX2 : ptrChartArea.AxisX;
            ptrYAxis = (ptrYAxis == ptrChartArea.AxisY) ? ptrChartArea.AxisY2 : ptrChartArea.AxisY;
            ptrXAxis.ScaleView.Zoom(ptrXAxis.PixelPositionToValue(XMin), ptrXAxis.PixelPositionToValue(XMax));
            ptrYAxis.ScaleView.Zoom(ptrYAxis.PixelPositionToValue(YMin), ptrYAxis.PixelPositionToValue(YMax));

            DialogResult = DialogResult.OK;
        }
예제 #3
0
 /// <summary>
 /// Converts an absolute pixel position along an axis to an axis value.
 /// This method only works in paint events.
 /// </summary>
 /// <param name="position">
 /// The pixel position.
 /// </param>
 /// <returns>
 /// A double value that represents the axis value.
 /// </returns>
 public double PixelPositionToValue(double position)
 {
     return(axis.PixelPositionToValue(position));
 }
        /// <summary>
        ///     Handles the zoom for the provided axis
        /// </summary>
        /// <param name="axis"></param>
        /// <param name="mouseLocation"></param>
        /// <param name="minValue"></param>
        /// <param name="maxValue"></param>
        /// <param name="zoomIn"></param>
        private void HandleZoomforAxis(Axis axis, int mouseLocation, double minValue, double maxValue, bool zoomIn)
        {
            double min = axis.ScaleView.ViewMinimum;
            double max = axis.ScaleView.ViewMaximum;

            double start, end;

            if (zoomIn)
            {
                start = Math.Floor(min + (axis.PixelPositionToValue(mouseLocation) - min)/2);
                end = Math.Floor(max - (max - axis.PixelPositionToValue(mouseLocation))/2);
            }
            else
            {
                start = Math.Floor(min - (axis.PixelPositionToValue(mouseLocation) - min));
                end = Math.Floor(max + (max - axis.PixelPositionToValue(mouseLocation)));
            }

            if (start <= minValue || end >= maxValue)
            {
                ResetZoom();
            }
            else
            {
                start = Math.Max(minValue, start);
                end = Math.Min(maxValue, end);

                if (start < end)
                {
                    axis.ScaleView.Zoom(start, end);
                }
            }
        }