Ejemplo n.º 1
0
        /// <summary>
        ///   Sets the value of the scroll range properties (see <see cref="ScrollMinX" />,
        ///   <see cref="ScrollMaxX" />, <see cref="YScrollRangeList" />, and
        ///   <see cref="Y2ScrollRangeList" /> based on the actual range of the data for
        ///   each corresponding <see cref="Axis" />.
        /// </summary>
        /// <remarks>
        ///   This method is called automatically by <see cref="AxisChange" /> if
        ///   <see cref="IsAutoScrollRange" />
        ///   is true.  Note that this will not be called if you call AxisChange directly from the
        ///   <see cref="GraphPane" />.  For example, zedGraphControl1.AxisChange() works properly, but
        ///   zedGraphControl1.GraphPane.AxisChange() does not.
        /// </remarks>
        public void SetScrollRangeFromData()
        {
            if (GraphPane == null)
            {
                return;
            }

            var grace = CalcScrollGrace(GraphPane.XAxis.Scale._rangeMin,
                                        GraphPane.XAxis.Scale._rangeMax);

            _xScrollRange.Min          = GraphPane.XAxis.Scale._rangeMin - grace;
            _xScrollRange.Max          = GraphPane.XAxis.Scale._rangeMax + grace;
            _xScrollRange.IsScrollable = true;

            for (var i = 0; i < GraphPane.YAxisList.Count; i++)
            {
                Axis axis = GraphPane.YAxisList[i];
                grace = CalcScrollGrace(axis.Scale._rangeMin, axis.Scale._rangeMax);
                var range = new ScrollRange(axis.Scale._rangeMin - grace,
                                            axis.Scale._rangeMax + grace,
                                            YScrollRangeList[i].IsScrollable);

                if (i >= YScrollRangeList.Count)
                {
                    YScrollRangeList.Add(range);
                }
                else
                {
                    YScrollRangeList[i] = range;
                }
            }

            for (var i = 0; i < GraphPane.Y2AxisList.Count; i++)
            {
                Axis axis = GraphPane.Y2AxisList[i];
                grace = CalcScrollGrace(axis.Scale._rangeMin, axis.Scale._rangeMax);
                var range = new ScrollRange(axis.Scale._rangeMin - grace,
                                            axis.Scale._rangeMax + grace,
                                            Y2ScrollRangeList[i].IsScrollable);

                if (i >= Y2ScrollRangeList.Count)
                {
                    Y2ScrollRangeList.Add(range);
                }
                else
                {
                    Y2ScrollRangeList[i] = range;
                }
            }

            //this.GraphPane.CurveList.GetRange( out scrollMinX, out scrollMaxX,
            //    out scrollMinY, out scrollMaxY, out scrollMinY2, out scrollMaxY2, false, false,
            //    this.GraphPane );
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        public ZedGraphControl()
        {
            InitializeComponent();
            InitializeComponentPartial();
            this._tooltip = ValuesToolTip.Create(this, this.pointToolTip);

            // 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 += ZedGraphControl_MouseDown;
            base.MouseUp   += ZedGraphControl_MouseUp;
            base.MouseMove += 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 = ZedGraphLocale.title_def;
            string xStr     = ZedGraphLocale.x_title_def;
            string yStr     = ZedGraphLocale.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.Add(new ScrollRange(true));
            Y2ScrollRangeList.Add(new ScrollRange(false));

            _zoomState      = null;
            _zoomStateStack = new ZoomStateStack();

            _graphDragState = new GraphDragState();

            CrossHairFontSpec = new FontSpec
            {
                FontColor = Color.Black,
                Size      = 9,
                Border    = { IsVisible = true },
                Fill      = { Color = Color.Beige, Brush = new SolidBrush(Color.Beige) },
                TextBrush = new SolidBrush(Color.Black)
            };
        }