// Constructor, which saves away all of the important information.
	// We assume that the lock on the "graphics" object is held by the caller.
	internal GraphicsContainer(Graphics graphics)
			{
				// Push this container onto the stack.
				this.graphics = graphics;
				next = graphics.stackTop;
				graphics.stackTop = this;

				// Save the graphics state information.
				clip = graphics.Clip;
				if(clip != null)
				{
					clip = clip.Clone();
				}
				compositingMode = graphics.CompositingMode;
				compositingQuality = graphics.CompositingQuality;
				interpolationMode = graphics.InterpolationMode;
				pageScale = graphics.PageScale;
				pageUnit = graphics.PageUnit;
				pixelOffsetMode = graphics.PixelOffsetMode;
				renderingOrigin = graphics.RenderingOrigin;
				smoothingMode = graphics.SmoothingMode;
				textContrast = graphics.TextContrast;
				textRenderingHint = graphics.TextRenderingHint;
				if (graphics.transform == null)
				{
					transform = null;
				}
				else
				{
					transform = Matrix.Clone(graphics.transform);
				}
			}
Example #2
0
        //public Image Image
        //{
        //    get
        //    {
        //        if (this.OwningColumn == null ||
        //            this.OwningTextAndImageColumn == null)
        //        {

        //            return imageValue;
        //        }
        //        else if (this.imageValue != null)
        //        {
        //            return this.imageValue;
        //        }
        //        else
        //        {
        //            return this.OwningTextAndImageColumn.Image;
        //        }
        //    }
        //    set
        //    {
        //        if (this.imageValue == value)
        //        {
        //            return;
        //        }

        //        this.imageValue = value;
        //        this.imageSize = value.Size;

        //        Padding inheritedPadding = this.InheritedStyle.Padding;

        //        this.Style.Padding = new Padding(inheritedPadding.Left,
        //            inheritedPadding.Top, inheritedPadding.Right - (imageSize.Width + 4),
        //            inheritedPadding.Bottom);
        //    }
        //}

        protected override void Paint(Graphics graphics, Rectangle clipBounds,
                                      Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState,
                                      object value, object formattedValue, string errorText,
                                      DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            this.cellBounds = cellBounds;

            int offset = 4;

            foreach (IconInfo info in icons)
            {
                if (info.Visible == false)
                {
                    continue;
                }

                offset += info.Image.Width + 4;
            }

            Padding inheritedPadding = this.InheritedStyle.Padding;

            this.Style.Padding = new Padding(inheritedPadding.Left,
                                             inheritedPadding.Top, inheritedPadding.Right - offset,
                                             inheritedPadding.Bottom);

            // Paint the base content
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState,
                       value, formattedValue, errorText, cellStyle,
                       advancedBorderStyle, paintParts);

            // Draw the image clipped to the cell.
            System.Drawing.Drawing2D.GraphicsContainer container = graphics.BeginContainer();

            graphics.SetClip(cellBounds);

            int x = cellBounds.Right - offset;

            foreach (IconInfo info in icons)
            {
                if (info.Visible == false)
                {
                    continue;
                }

                float vOffset = (cellBounds.Top + (cellBounds.Height * 0.5f)) - (info.Image.Height * 0.5f);

                graphics.DrawImageUnscaled(info.Image, x, (int)vOffset);

                x += info.Image.Width + 4;
            }

            graphics.EndContainer(container);
        }
Example #3
0
        /// <summary>
        /// Performs painting
        /// </summary>
        /// <param name="e">Paint-Event arguments</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            if (graphControl != null)
            {
                Graphics g = e.Graphics;



                Rectangle b = ZoomRectangle(Rectangle.Round(graphControl.extract.Rectangle));
                AutoScrollMinSize = b.Size;

                //GC.Collect();		this is expensive!!

                Rectangle r = Rectangle.Round(g.ClipBounds);

                // Scaling
                g.ScaleTransform(this.zoom, this.zoom);

                g.DrawRectangle(dashPen, 0, 0, graphControl.Width, graphControl.Height);

                // Paint structure of abstract
                graphControl.extract.Paint(g);

                // Paint netron panel bounding rectangle.
                Pen p = new Pen(Color.Blue, 2);

                System.Drawing.Drawing2D.GraphicsContainer gc = g.BeginContainer();
                drawingBounds = graphControl.ClientRectangle;

                //this rectangle represents the page
                //Pen ppage = new Pen(Brushes.Gray,1F);
                //ppage.DashStyle = DashStyle.Dash;
                //g.DrawRectangle(ppage, (drawingBounds.Width-graphControl.PageSize.Width)/2,(drawingBounds.Height-graphControl.PageSize.Height)/2,graphControl.PageSize.Width,graphControl.PageSize.Height);

                g.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y, MatrixOrder.Append);
                g.ScaleTransform(1 / graphControl.Zoom, 1 / graphControl.Zoom, MatrixOrder.Prepend);
                //if(graphControl.Zoom!=1)					g.TranslateTransform(graphControl.Width*(1-1/graphControl.Zoom)/2,graphControl.Height*(1-1/graphControl.Zoom)/2,MatrixOrder.Append);
                //drawingBounds.Offset( -graphControl.AutoScrollPosition.X, -graphControl.AutoScrollPosition.Y );


//				g.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y,MatrixOrder.Append);
//				g.ScaleTransform(this.currentZoomFactor,this.currentZoomFactor,MatrixOrder.Append);
//				g.TranslateTransform(-Width*(currentZoomFactor-1)/2,-Height*(currentZoomFactor-1)/2,MatrixOrder.Append);


                drawingBounds.Offset(-graphControl.AutoScrollPosition.X, -graphControl.AutoScrollPosition.Y);
                g.DrawRectangle(p, drawingBounds);

                g.EndContainer(gc);
            }
        }
Example #4
0
    protected override void Paint(Graphics graphics, Rectangle clipBounds,
                                  Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState,
                                  object value, object formattedValue, string errorText,
                                  DataGridViewCellStyle cellStyle,
                                  DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                  DataGridViewPaintParts paintParts)
    {
        // Paint the base content
        base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState,
                   value, formattedValue, errorText, cellStyle,
                   advancedBorderStyle, paintParts);

        if (this.Image != null)
        {
            // Draw the image clipped to the cell.
            System.Drawing.Drawing2D.GraphicsContainer container =
                graphics.BeginContainer();

            graphics.SetClip(cellBounds);
            graphics.DrawImageUnscaled(this.Image, cellBounds.Location);

            graphics.EndContainer(container);
        }
    }
        /// <summary>
        /// Primary function for painting the button. This method should be overridden instead of OnPaint.
        /// </summary>
        /// <param name="graphics">The graphics.</param>
        /// <param name="bounds">The bounds.</param>
        protected virtual void PaintButton(Graphics graphics, Rectangle bounds)
        {
            System.Diagnostics.Debug.WriteLine($"PaintButton: desMode:{this.IsDesignMode()};vsEnabled:{Application.RenderWithVisualStyles};vsOnOS:{VisualStyleInformation.IsSupportedByOS};btnState:{ButtonState};enabled:{Enabled};imgCt:{(ImageList != null ? ImageList.Images.Count : 0)}");

            if (InitializeRenderer())
            {
                if (OnGlass)
                {
                    rnd.DrawGlassBackground(graphics, bounds, bounds);
                }
                else
                {
                    rnd.DrawParentBackground(graphics, bounds, this);
                    rnd.DrawBackground(graphics, bounds);
                }
            }
            else
            {
                if (ImageList != null && ImageList.Images.Count > 0)
                {
                    int idx = (int)ButtonState - 1;
                    if (ImageList.Images.Count == 1)
                    {
                        idx = 0;
                    }
                    else if (ImageList.Images.Count == 2)
                    {
                        idx = ButtonState == PushButtonState.Disabled ? 1 : 0;
                    }
                    else if (ImageList.Images.Count == 3)
                    {
                        idx = ButtonState == PushButtonState.Normal ? 0 : idx - 1;
                    }
                    bool forceDisabled = !Enabled && ImageList.Images.Count == 1;
                    if (OnGlass)
                    {
                        VisualStyleRendererExtension.DrawGlassImage(null, graphics, bounds, ImageList.Images[idx], forceDisabled);
                    }
                    else
                    {
                        if (!Application.RenderWithVisualStyles && VisualStyleInformation.IsSupportedByOS)
                        {
                            System.Drawing.Drawing2D.GraphicsContainer g = graphics.BeginContainer();
                            Rectangle translateRect = bounds;
                            graphics.TranslateTransform(-bounds.Left, -bounds.Top);
                            PaintEventArgs pe = new PaintEventArgs(graphics, translateRect);
                            InvokePaintBackground(Parent, pe);
                            InvokePaint(Parent, pe);
                            graphics.ResetTransform();
                            graphics.EndContainer(g);
                        }
                        else
                        {
                            graphics.Clear(Parent.BackColor);
                        }
                        if (forceDisabled)
                        {
                            ControlPaint.DrawImageDisabled(graphics, ImageList.Images[idx], 0, 0, Color.Transparent);
                        }
                        else
                        {
                            //base.ImageList.Draw(graphics, bounds.X, bounds.Y, bounds.Width, bounds.Height, idx);
                            //VisualStyleRendererExtender.DrawGlassImage(null, graphics, bounds, base.ImageList.Images[idx], forceDisabled); // Not 7
                            graphics.DrawImage(ImageList.Images[idx], bounds, bounds, GraphicsUnit.Pixel); // Works on XP, not 7, with Parent.BackColor
                        }
                    }
                }

                /*else if (this.ImageList != null && this.ImageList.Images.Count > 1)
                 *              {
                 *                      int idx = (int)ButtonState - 1;
                 *                      if (this.ImageList.Images.Count == 2)
                 *                              idx = ButtonState == PushButtonState.Disabled ? 1 : 0;
                 *                      if (this.ImageList.Images.Count == 3)
                 *                              idx = ButtonState == PushButtonState.Normal ? 0 : idx - 1;
                 *                      if (rnd != null && !this.IsDesignMode() && DesktopWindowManager.IsCompositionEnabled())
                 *                              rnd.DrawGlassIcon(graphics, bounds, this.ImageList, idx);
                 *                      else
                 *                              this.ImageList.Draw(graphics, bounds.X, bounds.Y, bounds.Width, bounds.Height, idx);
                 *              }*/
                // No image so draw standard button
                else
                {
                    ButtonRenderer.DrawParentBackground(graphics, bounds, this);
                    ButtonRenderer.DrawButton(graphics, bounds, ButtonState);
                }
            }

            if (Focused)
            {
                ControlPaint.DrawFocusRectangle(graphics, bounds);
            }
        }
Example #6
0
        /// <summary>
        /// Draws the image.
        /// </summary>
        /// <param name="graphics">The graphics.</param>
        /// <param name="rect">The rect.</param>
        /// <param name="image">The image.</param>
        /// <param name="imageAlign">The image align.</param>
        public static void DrawImage(Graphics graphics, Rectangle rect, Image image, ContentAlignment imageAlign)
        {
            if (image != null)
            {
                // Draw the image clipped to the cell.
                System.Drawing.Drawing2D.GraphicsContainer container = graphics.BeginContainer();

                graphics.SetClip(rect);

                int x = rect.X;
                int y = rect.Y;

                switch (imageAlign)
                {
                case ContentAlignment.BottomCenter:
                    x += (rect.Width - image.Width) / 2;
                    y += rect.Height - image.Height;
                    break;

                case ContentAlignment.BottomLeft:
                    y += rect.Height - image.Height;
                    break;

                case ContentAlignment.BottomRight:
                    x += rect.Width - image.Width;
                    y += rect.Height - image.Height;
                    break;

                case ContentAlignment.MiddleCenter:
                    x += (rect.Width - image.Width) / 2;
                    y += (rect.Height - image.Height) / 2;
                    break;

                case ContentAlignment.MiddleLeft:
                    y += (rect.Height - image.Height) / 2;
                    break;

                case ContentAlignment.MiddleRight:
                    x += rect.Width - image.Width;
                    break;

                case ContentAlignment.TopCenter:
                    x += (rect.Width - image.Width) / 2;
                    break;

                case ContentAlignment.TopLeft:
                    break;

                case ContentAlignment.TopRight:
                    x += rect.Width - image.Width;
                    break;

                default:
                    break;
                }

                graphics.DrawImageUnscaled(image, x, y);

                graphics.EndContainer(container);
            }
        }
	// Constructor.  Call this with the context lock held.
	internal GraphicsState(Graphics graphics)
			{
				container = new GraphicsContainer(graphics);
			}