예제 #1
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        public ZedGraphControl()
        {
            InitializeComponent();

            // These commands do nothing, but they get rid of the compiler warnings for
            // unused events
            bool b = MouseDown == null || MouseUp == null || MouseMove == null;

            // Link in these events from the base class, since we disable them from this class.
            base.MouseDown += new System.Windows.Forms.MouseEventHandler( this.ZedGraphControl_MouseDown );
            base.MouseUp += new System.Windows.Forms.MouseEventHandler( this.ZedGraphControl_MouseUp );
            base.MouseMove += new System.Windows.Forms.MouseEventHandler( this.ZedGraphControl_MouseMove );

            //this.MouseWheel += new System.Windows.Forms.MouseEventHandler( this.ZedGraphControl_MouseWheel );

            // Use double-buffering for flicker-free updating:
            SetStyle( ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint
                | ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw, true );
            //isTransparentBackground = false;
            //SetStyle( ControlStyles.Opaque, false );
            SetStyle( ControlStyles.SupportsTransparentBackColor, true );
            //this.BackColor = Color.Transparent;

            Rectangle rect = new Rectangle( 0, 0, this.Size.Width, this.Size.Height );
            _masterPane = new MasterPane( "", rect );
            _masterPane.Margin.All = 0;
            _masterPane.Title.IsVisible = false;

            string titleStr = Properties.Resources.Zedgraph_title_def;
            string xStr = Properties.Resources.Zedgraph_x_title_def;
            string yStr = Properties.Resources.Zedgraph_y_title_def;

            //GraphPane graphPane = new GraphPane( rect, "Title", "X Axis", "Y Axis" );
            GraphPane graphPane = new GraphPane( rect, titleStr, xStr, yStr );
            using ( Graphics g = this.CreateGraphics() )
            {
                graphPane.AxisChange( g );
                //g.Dispose();
            }
            _masterPane.Add( graphPane );

            this.hScrollBar1.Minimum = 0;
            this.hScrollBar1.Maximum = 100;
            this.hScrollBar1.Value = 0;

            this.vScrollBar1.Minimum = 0;
            this.vScrollBar1.Maximum = 100;
            this.vScrollBar1.Value = 0;

            _xScrollRange = new ScrollRange( true );
            _yScrollRangeList = new ScrollRangeList();
            _y2ScrollRangeList = new ScrollRangeList();

            _yScrollRangeList.Add( new ScrollRange( true ) );
            _y2ScrollRangeList.Add( new ScrollRange( false ) );

            _zoomState = null;
            _zoomStateStack = new ZoomStateStack();
        }
        /// <summary>
        /// Zoom a specified pane in or out according to the specified zoom fraction.
        /// </summary>
        /// <remarks>
        /// The zoom will occur on the <see cref="XAxis" />, <see cref="YAxis" />, and
        /// <see cref="Y2Axis" /> only if the corresponding flag, <see cref="IsEnableHZoom" /> or
        /// <see cref="IsEnableVZoom" />, is true.  Note that if there are multiple Y or Y2 axes, all of
        /// them will be zoomed.
        /// </remarks>
        /// <param name="pane">The <see cref="GraphPane" /> instance to be zoomed.</param>
        /// <param name="zoomFraction">The fraction by which to zoom, less than 1 to zoom in, greater than
        /// 1 to zoom out.  For example, 0.9 will zoom in such that the scale is 90% of what it was
        /// originally.</param>
        /// <param name="centerPt">The screen position about which the zoom will be centered.  This
        /// value is only used if <see paramref="isZoomOnCenter" /> is true.
        /// </param>
        /// <param name="isZoomOnCenter">true to cause the zoom to be centered on the point
        /// <see paramref="centerPt" />, false to center on the <see cref="Chart.Rect" />.
        /// </param>
        /// <param name="isRefresh">true to force a refresh of the control, false to leave it unrefreshed</param>
        protected void ZoomPane( GraphPane pane, double zoomFraction, PointF centerPt,
					bool isZoomOnCenter, bool isRefresh )
        {
            double x;
            double x2;
            double[] y;
            double[] y2;

            pane.ReverseTransform( centerPt, out x, out x2, out y, out y2 );

            if ( _isEnableHZoom )
            {
                ZoomScale( pane.XAxis, zoomFraction, x, isZoomOnCenter );
                ZoomScale( pane.X2Axis, zoomFraction, x2, isZoomOnCenter );
            }
            if ( _isEnableVZoom )
            {
                for ( int i = 0; i < pane.YAxisList.Count; i++ )
                    ZoomScale( pane.YAxisList[i], zoomFraction, y[i], isZoomOnCenter );
                for ( int i = 0; i < pane.Y2AxisList.Count; i++ )
                    ZoomScale( pane.Y2AxisList[i], zoomFraction, y2[i], isZoomOnCenter );
            }

            using ( Graphics g = this.CreateGraphics() )
            {
                pane.AxisChange( g );
                //g.Dispose();
            }

            this.SetScroll( this.hScrollBar1, pane.XAxis, _xScrollRange.Min, _xScrollRange.Max );
            this.SetScroll( this.vScrollBar1, pane.YAxis, _yScrollRangeList[0].Min,
                _yScrollRangeList[0].Max );

            if ( isRefresh )
                Refresh();
        }
예제 #3
0
 /// <summary>
 /// Restore the scale ranging to automatic mode, and recalculate the
 /// <see cref="Axis"/> scale ranges
 /// </summary>
 /// <param name="pane">
 /// A reference to the <see cref="GraphPane"/> object that is the parent or
 /// owner of this object.
 /// </param>
 /// <param name="g">
 /// A graphic device object to be drawn into.  This is normally e.Graphics from the
 /// PaintEventArgs argument to the Paint() method.
 /// </param>
 /// <seealso cref="ZedGraph.Scale.MinAuto"/>
 /// <seealso cref="ZedGraph.Scale.MaxAuto"/>
 /// <seealso cref="ZedGraph.Scale.MajorStepAuto"/>
 /// <seealso cref="ZedGraph.Scale.MagAuto"/>
 /// <seealso cref="ZedGraph.Scale.FormatAuto"/>
 public void ResetAutoScale( GraphPane pane, Graphics g )
 {
     _scale._minAuto = true;
     _scale._maxAuto = true;
     _scale._majorStepAuto = true;
     _scale._minorStepAuto = true;
     _crossAuto = true;
     _scale._magAuto = true;
     //this.numDecAuto = true;
     _scale._formatAuto = true;
     pane.AxisChange( g );
 }