System.Drawing.Graphics.BeginContainer C# (CSharp) Method

BeginContainer() public method

public BeginContainer ( RectangleF dstRect, RectangleF srcRect, GraphicsUnit unit ) : GraphicsContainer
dstRect RectangleF
srcRect RectangleF
unit GraphicsUnit
return GraphicsContainer
        public GraphicsContainer BeginContainer(RectangleF dstRect, RectangleF srcRect, GraphicsUnit unit)
        {
            var container = BeginContainer();

            var srcRect1 = srcRect;

            // If the source units are not the same we need to convert them
            // The reason we check for Pixel here is that our graphics already has the Pixel's baked into the model view transform
            if (unit != graphicsUnit && unit != GraphicsUnit.Pixel)
            {
                ConversionHelpers.GraphicsUnitConversion (unit, graphicsUnit, DpiX, DpiX,  ref srcRect1);
            }

            TranslateTransform(dstRect.X, dstRect.Y);

            float scaleX = dstRect.Width/srcRect1.Width;
            float scaleY = dstRect.Height/srcRect1.Height;
            ScaleTransform(scaleX, scaleY);

            return container;
        }

Same methods

Graphics::BeginContainer ( ) : GraphicsContainer
Graphics::BeginContainer ( Rectangle dstRect, Rectangle srcRect, GraphicsUnit unit ) : GraphicsContainer

Usage Example

Example #1
1
		public void Draw(Graphics g)
		{
			g.FillRectangle(SystemBrushes.AppWorkspace, Bounds);

			g.DrawRectangle(Pens.Black, mCanvasMarginWidth - 1, mCanvasMarginHeight - 1, 800 + 1, 600 + 1);

			g.TranslateTransform(mCanvasMarginWidth, mCanvasMarginHeight);
			GraphicsContainer containerState = g.BeginContainer();
			g.SmoothingMode = SmoothingMode.HighQuality;

			DrawCanvas(g);

			g.SmoothingMode = SmoothingMode.Default;
			g.EndContainer(containerState);
			g.TranslateTransform(-mCanvasMarginWidth, -mCanvasMarginHeight);


			//mCanvasBufferGraphics.FillRectangle(SystemBrushes.AppWorkspace, Bounds);

			//mCanvasBufferGraphics.DrawRectangle(Pens.Black, mCanvasMarginWidth - 1, mCanvasMarginHeight - 1, 800 + 1, 600 + 1);

			//DrawCanvas(mCanvasBufferGraphics);


			//Rectangle src = Bounds;
			//Rectangle dest = new Rectangle(0, 0, (int)(Bounds.Width * mScale), (int)(Bounds.Height * mScale));
			//dest.X = (Bounds.Width / 2) - (dest.Width / 2);
			//dest.Y = (Bounds.Height / 2) - (dest.Height / 2);

			//g.DrawImage(mCanvasBufferImage, dest, src, GraphicsUnit.Pixel);
		}
All Usage Examples Of System.Drawing.Graphics::BeginContainer