Transparent Controls
-
I recently wrote a couple of lines of code which lets me move controls on my form just by dragging them with the mouse. Now that I can move controls around, I noticed something. A control with a transparent background will allow you to see the background of your form, but it still hides other controls on my Form. Furthermore, if I have different colors on my Form's background, I'll get a distortion momentarily on my control as it moves around. I'd like to be able to have movable controls without either of these issues. So my question is this: Can I do something to my controls so that the transparent background actually works how I want it to? Can I somehow change the region my control takes up so that I don't have this extra "space" around it? For instance, if I had a ball, why do I need the entire square? Thanks for any help
-
I recently wrote a couple of lines of code which lets me move controls on my form just by dragging them with the mouse. Now that I can move controls around, I noticed something. A control with a transparent background will allow you to see the background of your form, but it still hides other controls on my Form. Furthermore, if I have different colors on my Form's background, I'll get a distortion momentarily on my control as it moves around. I'd like to be able to have movable controls without either of these issues. So my question is this: Can I do something to my controls so that the transparent background actually works how I want it to? Can I somehow change the region my control takes up so that I don't have this extra "space" around it? For instance, if I had a ball, why do I need the entire square? Thanks for any help
DougW48 wrote: Can I somehow change the region my control takes up so that I don't have this extra "space" around it? For instance, if I had a ball, why do I need the entire square? Because every control is a window and uses a rectangular region. If you want to add a clipping region to your control, override
OnPaint
and set theGraphics.Clip
property to aRegion
that contains only what you want (like a circle for your aforementioned control).Microsoft MVP, Visual C# My Articles