By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,542 Members | 1,740 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,542 IT Pros & Developers. It's quick & easy.

User Controls transparent

P: n/a
I'm using VS 2003, C#.Net 2003.

I built a simple windows form app. with the following attributes:
- has a BackgroundImage set to a jpeg

I built a very simple user control that contains a picture box set to an
icon. The UserControl constructor sets
SetStyle( ControlStyles.SupportTransparentBackColor, true);
this.BackColor = Color.Transparent;
The control does nothing except display the icon.

In the main windows form, on formload event, I declare and instantiate 30
user controls and give them various locations on the main form.

The Problem: When the main form loads, displays or becomes active, there
are transparent (to the desktop) rectangles in locations where the user
controls are to be displayed. The transparent rectangles then fill in with
the mainform background image and the icons in the usercontrol.

I have identified this issue to be linked the BackColor = Color.Transparent.
If I set the BackColor to a color, this issue goes away. Offcourse, I now
have a solid box around my control

Is there a way keep the usercontrol backgroud transparent while eliminating
this annoying transparent rectangle issue?

Mar 7 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
We have been having similar problems in our application when the form
has a number of controls. This behavior is caused by how .NET handles
painting. Each parent will only paint its area not obscured by child
controls. So, the Form won't paint behind the UserControls after they
are added to the Controls collection of the Form. The reason why you
don't see the transparent rectangles if you set their background color
is that their PaintBackground event will fill the area with their
BackColor property. If it is transparent, nothing will be drawn in
that rectangle until the UserControl's Paint event is fired.

We found that it helps, but does not eliminate, to call Refresh() when
the form is shown. Since you are adding the controls during the
FormLoad event, try calling Refresh() before adding the controls. This
will force the form to repaint itself, and won't leave space for the
controls. While the UserControls won't be painted immediately (you
will probably see them rapidly appear on the screen, just not at once),
you at least won't see "holes" in your Form.

Hope this helps.
Abe

Mar 8 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.