ZForge.Controls.ExplorerBar.Expando.PaintTransparentBackground C# (CSharp) Method

PaintTransparentBackground() protected method

Simulates a transparent background by getting the Expandos parent to paint its background and foreground into the specified Graphics at the specified location
protected PaintTransparentBackground ( Graphics g, Rectangle clipRect ) : void
g System.Drawing.Graphics The Graphics used to paint the background
clipRect System.Drawing.Rectangle The Rectangle that represents the rectangle /// in which to paint
return void
        protected void PaintTransparentBackground(Graphics g, Rectangle clipRect)
        {
            // check if we have a parent
            if (this.Parent != null)
            {
                // convert the clipRects coordinates from ours to our parents
                clipRect.Offset(this.Location);

                PaintEventArgs e = new PaintEventArgs(g, clipRect);

                // save the graphics state so that if anything goes wrong
                // we're not fubar
                GraphicsState state = g.Save();

                try
                {
                    // move the graphics object so that we are drawing in
                    // the correct place
                    g.TranslateTransform((float) -this.Location.X, (float) -this.Location.Y);

                    // draw the parents background and foreground
                    this.InvokePaintBackground(this.Parent, e);
                    this.InvokePaint(this.Parent, e);

                    return;
                }
                finally
                {
                    // reset everything back to where they were before
                    g.Restore(state);
                    clipRect.Offset(-this.Location.X, -this.Location.Y);
                }
            }

            // we don't have a parent, so fill the rect with
            // the default control color
            g.FillRectangle(SystemBrushes.Control, clipRect);
        }