So, what I've got is this:
Expand|Select|Wrap|Line Numbers
- VistaGroupBox
- +-Panel
- +-VistaButton
Expand|Select|Wrap|Line Numbers
- public delegate void InvokePaintDelegate(Control c, PaintEventArgs e);
- public delegate void InvokePaintBackgroundDelegate(Control c, PaintEventArgs e);
- /// <summary>
- /// This function looks like a mess primarily because of the #if ... #endifs. The problem is, the "BROKEN WINDOWS"
- /// section is how WINDOWS does it, which is a problem for going through multiple transparent areas for whatever reason.
- /// MY_CORRECT works if you're only going from user drawn transparency to user drawn transparency - that is, none of your
- /// controls use Control.OnPaintBackground (like a Transparent Panel). WINDOWS_HACK works in all conditions - too bad it uses
- /// a bit more memory due to the image creation.
- /// </summary>
- /// <param name="c">The control to paint the parent to</param>
- /// <param name="pevent">The PaintEventArgs from the OnPaintBackground call</param>
- /// <param name="InvokePaint">The control's InvokePaint method - because it is protected.</param>
- /// <param name="InvokePaintBackground">The control's InvokePaintBackground method - because it is protected.</param>
- public static void DrawParent(Control c, PaintEventArgs pevent, InvokePaintDelegate InvokePaint, InvokePaintBackgroundDelegate InvokePaintBackground)
- {
- PaintEventArgs parent_pe;
- GraphicsState state;
- Rectangle clipRect;
- Graphics g;
- #if BROKEN_WINDOWS
- IntPtr hdc = pevent.Graphics.GetHdc();
- g = Graphics.FromHdc(hdc);
- if (c.Region != null)
- g.Clip = c.Region;
- else
- g.Clip = new Region(c.ClientRectangle);
- clipRect = new Rectangle(pevent.ClipRectangle.X + c.Left, pevent.ClipRectangle.Y + c.Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height);
- #elif MY_CORRECT
- g = pevent.Graphics;
- clipRect = new Rectangle(pevent.ClipRectangle.X + c.Left, pevent.ClipRectangle.Y + c.Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height);
- #elif WINDOWS_HACK
- Image img = new Bitmap(c.Parent.Width, c.Parent.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
- g = Graphics.FromImage(img);
- clipRect = new Rectangle(c.Location, c.Size);
- g.Clip = new Region(clipRect);
- #endif
- parent_pe = new PaintEventArgs(g, clipRect);
- state = g.Save();
- #if !WINDOWS_HACK
- g.TranslateTransform(-c.Left, -c.Top);
- #endif
- InvokePaintBackground(c.Parent, parent_pe);
- g.Restore(state);
- state = g.Save();
- #if !WINDOWS_HACK
- g.TranslateTransform(-c.Left, -c.Top);
- #endif
- InvokePaint(c.Parent, parent_pe);
- g.Restore(state);
- #if BROKEN_WINDOWS
- g.Dispose();
- pevent.Graphics.ReleaseHdc(hdc);
- #elif WINDOWS_HACK
- g.Dispose();
- pevent.Graphics.DrawImage(img, new Rectangle(new Point(0,0), c.Size), new Rectangle(c.Location, c.Size), GraphicsUnit.Pixel);
- img.Dispose();
- #endif
- }
Anyone got some time to help me figure this one out?