/// <summary>
        /// Rendering method used by the print context menu items
        /// </summary>
        /// <param name="sender">The applicable <see cref="PrintDocument" />.</param>
        /// <param name="e">A <see cref="PrintPageEventArgs" /> instance providing
        /// page bounds, margins, and a Graphics instance for this printed output.
        /// </param>
        private void Graph_PrintPage(object sender, PrintPageEventArgs e)
        {
            PrintDocument pd = sender as PrintDocument;

            MasterPane mPane = this.MasterPane;

            bool[] isPenSave  = new bool[mPane.PaneList.Count + 1];
            bool[] isFontSave = new bool[mPane.PaneList.Count + 1];
            isPenSave[0]  = mPane.IsPenWidthScaled;
            isFontSave[0] = mPane.IsFontsScaled;
            for (int i = 0; i < mPane.PaneList.Count; i++)
            {
                isPenSave[i + 1]  = mPane[i].IsPenWidthScaled;
                isFontSave[i + 1] = mPane[i].IsFontsScaled;
                if (_isPrintScaleAll)
                {
                    mPane[i].IsPenWidthScaled = true;
                    mPane[i].IsFontsScaled    = true;
                }
            }

            RectangleF saveRect = mPane.Rect;
            SizeF      newSize  = mPane.Rect.Size;

            if (_isPrintFillPage && _isPrintKeepAspectRatio)
            {
                float xRatio = (float)e.MarginBounds.Width / (float)newSize.Width;
                float yRatio = (float)e.MarginBounds.Height / (float)newSize.Height;
                float ratio  = Math.Min(xRatio, yRatio);

                newSize.Width  *= ratio;
                newSize.Height *= ratio;
            }
            else if (_isPrintFillPage)
            {
                newSize = e.MarginBounds.Size;
            }

            mPane.ReSize(e.Graphics, new RectangleF(e.MarginBounds.Left,
                                                    e.MarginBounds.Top, newSize.Width, newSize.Height));
            mPane.Draw(e.Graphics);

            using (Graphics g = this.CreateGraphics())
            {
                mPane.ReSize(g, saveRect);

                //g.Dispose();
            }

            mPane.IsPenWidthScaled = isPenSave[0];
            mPane.IsFontsScaled    = isFontSave[0];
            for (int i = 0; i < mPane.PaneList.Count; i++)
            {
                mPane[i].IsPenWidthScaled = isPenSave[i + 1];
                mPane[i].IsFontsScaled    = isFontSave[i + 1];
            }
        }
Example #2
0
        //		Thread t = null;
        //DrawingThread dt = null;

        /*
         *
         *              /// <summary>
         *              ///
         *              /// </summary>
         *              /// <param name="dtdobj"></param>
         *              public void DoDrawingThread( object dtdobj )
         *              {
         *                      try
         *                      {
         *                              DrawingThreadData dtd = (DrawingThreadData) dtdobj;
         *
         *                              if ( dtd._g != null && dtd._masterPane != null )
         *                                      dtd._masterPane.Draw( dtd._g );
         *
         *                              //				else
         *                              //				{
         *                              //					using ( Graphics g2 = CreateGraphics() )
         *                              //						_masterPane.Draw( g2 );
         *                              //				}
         *                      }
         *                      catch
         *                      {
         *                      }
         *              }
         */

        /// <summary>
        /// Called when the control has been resized.
        /// </summary>
        /// <param name="sender">
        /// A reference to the control that has been resized.
        /// </param>
        /// <param name="e">
        /// An EventArgs object.
        /// </param>
        protected void ZedGraphControl_ReSize(object sender, System.EventArgs e)
        {
            lock (this)
            {
                if (BeenDisposed || _masterPane == null)
                {
                    return;
                }

                Size newSize = this.Size;

                if (_isShowHScrollBar)
                {
                    hScrollBar1.Visible  = true;
                    newSize.Height      -= this.hScrollBar1.Size.Height;
                    hScrollBar1.Location = new Point(0, newSize.Height);
                    hScrollBar1.Size     = new Size(newSize.Width, hScrollBar1.Height);
                }
                else
                {
                    hScrollBar1.Visible = false;
                }

                if (_isShowVScrollBar)
                {
                    vScrollBar1.Visible  = true;
                    newSize.Width       -= this.vScrollBar1.Size.Width;
                    vScrollBar1.Location = new Point(newSize.Width, 0);
                    vScrollBar1.Size     = new Size(vScrollBar1.Width, newSize.Height);
                }
                else
                {
                    vScrollBar1.Visible = false;
                }

                using (Graphics g = this.CreateGraphics())
                {
                    _masterPane.ReSize(g, new RectangleF(0, 0, newSize.Width, newSize.Height));

                    //g.Dispose();
                }
                this.Invalidate();
            }
        }
Example #3
0
        /// <summary>
        /// stub method that passes control for the render event to the the registered
        /// event handler.
        /// </summary>
        protected virtual void OnDrawPane( Graphics g, MasterPane mp )
        {
            ZedGraphWebControlEventHandler handler;
            handler = (ZedGraphWebControlEventHandler)Events[_eventRender];

            MasterPaneFill.CopyTo( mp.Fill );
            MasterPaneBorder.CopyTo( mp.Border );

            if ( ( handler == null ) && ( CurveList.Count == 0 ) && ( GraphObjList.Count == 0 ) )
            {
                // default with the sample graph if no callback provided
                foreach ( GraphPane p in mp.PaneList )
                {
                    ZedGraphWeb.RenderDemo( g, p );
                }
            }
            else
            {
                foreach ( GraphPane p in mp.PaneList )
                {
                    // Add visual designer influences here - first!!
                    SetWebProperties( g, p );

                    // Add DataSource values if available before the callback
                    PopulateByDataSource( g, p );

                    //Add Graph Items
                    AddWebGraphItems( g, p );
                }

                //TODO: verify callback regression test
                // Add custom callback tweeking next
                if ( handler != null )
                    handler( this, g, mp );

                // Set the layout according to user preferences
                mp.ReSize( g );
            }
        }
Example #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="OutputStream"></param>
        /// <param name="Format"></param>
        /// <param name="bShowTransparency">if true, draw squares instead of leaving the
        /// background transparent</param>
        /// <remarks>
        /// bShowTransparency is set to true in design mode, to false otherwise.
        /// </remarks>
        protected MasterPane CreateGraph( System.IO.Stream OutputStream, ImageFormat Format,
				bool bShowTransparency )
        {
            RectangleF rect = new RectangleF( 0, 0, this.Width, this.Height );
            MasterPane mp = new MasterPane( string.Empty, rect );
            mp.Margin.All = 0;
            mp.Fill.IsVisible = false;
            mp.Border.IsVisible = false;

            // create all required panes
            //for ( int i = 0; i < this.PaneCount; i++ )
            //{
            mp.Add( new GraphPane( rect, Title, string.Empty, string.Empty ) );
            //}

            // create output bitmap container
            Bitmap image = new Bitmap( this.Width, this.Height );
            using ( Graphics g = Graphics.FromImage( image ) )
            {
                // Apply layout plan
                //mp.SetLayout( this.PaneLayout );
                mp.ReSize( g, rect );

                // Use callback to gather more settings and data values
                OnDrawPane( g, mp );

                // Allow designer control of axischange
                if ( this.AxisChanged ) mp.AxisChange( g );

                // Render the graph to a bitmap
                if ( bShowTransparency && mp.Fill.Color.A != 255 )
                {
                    //Show the transparency as white/gray filled squares
                    // We need to add the resource namespace to its name
                    //string resourceName = string.Format( "{0}.transparency.png", GetType().Namespace );
                    string resourceName = "ZedGraph.ZedGraph.transparency.png";
                    Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream( resourceName );

                    if ( stream == null )
                        throw new Exception( "Does the Build Action of the resource " + resourceName + " is set to Embedded Resource ?" );

                    using ( System.Drawing.Image brushImage = new Bitmap( stream ) )
                    using ( TextureBrush brush = new TextureBrush( brushImage, WrapMode.Tile ) )
                    {
                        g.FillRectangle( brush, 0, 0, this.Width, this.Height );
                    }
                    stream.Close();
                }
                mp.Draw( g );
            }

            // Stream the graph out
            MemoryStream ms = new MemoryStream();
            image.Save( ms, Format );

            //TODO: provide caching options
            ms.WriteTo( OutputStream );

            return mp;
        }