I am trying to use this tutorial so that I can have a transparent button. It works fine for the main background, but it doesn't draw over the other children. If I use BringToFront()
it then doesn't have the other child's drawing where it should be.
I have started to get around it by adding this to the code:
foreach (Control child in Parent.Controls) {
if(child != this) {
InvokePaintBackground(child, pea);
InvokePaint(child, pea);
}
}
And although I get some of what I want, it's in the wrong location (on the left instead of in the middle where it shoudl be) and the shapes which are drawn in the child's paint event also aren't showing up.
How can I modify so that I will have all of the other children as well giving the full illusion of transparency?
Note: I'm not worried about paining for anybody but other children, as I know that there aren't any, and there are pleny of other places to find out how to get all of the children recursively.
Thanks to C.Evenhuis answer, its now working. My implementation is simple (only one other child), so this is my code. For future readers, be sure to read that post though to get a fll scope.
using (PaintEventArgs pea = new PaintEventArgs(e.Graphics, rect)) {
pea.Graphics.SetClip(rect);
InvokePaintBackground(Parent, pea);
InvokePaint(Parent, pea);
foreach (Control child in Parent.Controls) {
if (child != this) {
pea.Graphics.ResetTransform();
pea.Graphics.TranslateTransform(child.Left - Left, child.Top - Top);
InvokePaintBackground(child, pea);
InvokePaint(child, pea);
}
}
}