简体   繁体   中英

Foreach control in tabpage

So I have this form with a background. The problem was that I had a huge drop, performance wise. So someone told me to just use a picturebox and use "Set to back" to get the same effect.

Now the problem is that the background of my controls are not transparent anymore, but the same as the form background.

So someome told me to use this code:

control.Parent = pictureboxBackground;
control.BackColor = Color.Transparent;

But now I have to write those two lines of code for all of my 20 controls.

So I tried to use the following foreach statement:

foreach (Control but in tabPage2.Controls)
{
    but.Parent = pictureBox1;
    but.BackColor = Color.Transparent;
}   

But now only half of my controls' backcolors are made transparent.

for example:

Label1 is transparent

label2 isn't

button1 isn't

button2 is transparent

What am I doing wrong?

Try this:

foreach (Control but in tabPage2.Controls)
{
  but.Parent = pictureBox1;
  but.BackColor = Color.Transparent;
}

Application.DoEvents();

or

foreach (Control but in tabPage2.Controls)
{
  but.Parent = pictureBox1;
  but.BackColor = Color.Transparent;
  but.Invalidate();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM