简体   繁体   English

标签页中的Foreach控件

[英]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. 但是现在我必须为我的所有20个控件编写这两行代码。

So I tried to use the following foreach statement: 所以我尝试使用以下foreach语句:

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 Label1是透明的

label2 isn't label2不是

button1 isn't button1不是

button2 is transparent button2是透明的

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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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