OnWindowlessPaint() protected method

protected OnWindowlessPaint ( WindowlessControlHost sender, Graphics graphics, Point origin, Rectangle clipRectangle ) : void
sender WindowlessControlHost
graphics System.Drawing.Graphics
origin Point
clipRectangle System.Drawing.Rectangle
return void
コード例 #1
0
        protected void OnWindowlessPaint(WindowlessControlHost sender, Graphics graphics, Point origin, Rectangle clipRectangle)
        {
            SyncWindows();

            Rectangle rect       = clipRectangle;
            Graphics  g          = graphics;
            Point     o          = origin;
            Bitmap    backBuffer = null;
            Region    oldClip    = null;

            if (DoubleBuffer || sender == this)
            {
                PrepareBackBuffer(clipRectangle);
                o = Point.Empty;
                if (DoubleBuffer)
                {
                    g          = myGraphics;
                    backBuffer = myBackBuffer;
                    PrepareDirtyRegion();

                    if (myDirtyRegion.IsVisible(clipRectangle))
                    {
                        RectangleF regionBounds = myDirtyRegion.GetBounds(myGraphics);
                        rect = new Rectangle((int)Math.Round(regionBounds.X, 0), (int)Math.Round(regionBounds.Y, 0), (int)Math.Round(regionBounds.Width, 0), (int)Math.Round(regionBounds.Height, 0));
                        rect.Intersect(clipRectangle);
                        myDirtyRegion.Exclude(rect);
                    }
                    else
                    {
                        rect = Rectangle.Empty;
                    }
                }
                else
                {
                    o = new Point(-clipRectangle.X, -clipRectangle.Y);
                    clipRectangle.X = 0;
                    clipRectangle.Y = 0;
                    g          = ourGraphics;
                    backBuffer = ourBackBuffer;
                }

                oldClip = g.Clip;
                g.Clip  = myDummyRegion;
                oldClip.MakeEmpty();
                oldClip.Union(clipRectangle);
                if (DoubleBuffer)
                {
                    oldClip.Intersect(myDirtyRegion);
                }
                g.Clip = oldClip;
            }

            if (rect.Width != 0 && rect.Height != 0)
            {
                if (BackColor == Color.Transparent)
                {
                    WindowlessControlHost host = Parent as WindowlessControlHost;
                    if (host != null)
                    {
                        Rectangle parentRect = rect;
                        parentRect.X += Left;
                        parentRect.Y += Top;
                        host.OnWindowlessPaint(sender, g, new Point(o.X - Left, o.Y - Top), parentRect);
                    }
                    else
                    {
                        g.FillRectangle(PlatformBitmap.TransparentBrush, origin.X + clipRectangle.X, origin.Y + clipRectangle.Y, clipRectangle.Width, clipRectangle.Height);
                    }
                }
                WindowlessPaintHost(this, g, o, rect);
            }

            if (DoubleBuffer || sender == this)
            {
                Rectangle sourceRectangle = clipRectangle;
                if (sender == this)
                {
                    clipRectangle.X   = -o.X;
                    clipRectangle.Y   = -o.Y;
                    sourceRectangle.X = 0;
                    sourceRectangle.Y = 0;
                }
                g.Clip = oldClip;
                if (graphics != null)
                {
                    graphics.DrawImage(backBuffer, new Rectangle(origin.X + clipRectangle.Left, origin.Y + clipRectangle.Top, clipRectangle.Width, clipRectangle.Height), sourceRectangle, GraphicsUnit.Pixel);
                }
            }
        }