gpt4 book ai didi

c# - tabpage中的foreach控件

转载 作者:行者123 更新时间:2023-11-30 16:52:00 24 4
gpt4 key购买 nike

所以我有这个带有背景的表格。问题是我在性能方面有很大的下降。所以有人告诉我只使用图片框并使用“设置为后退”来获得相同的效果。

现在的问题是我的控件的背景不再是透明的,而是和窗体背景一样。

所以有人告诉我使用这段代码:

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

但现在我必须为所有 20 个控件编写这两行代码。

所以我尝试使用以下 foreach 语句:

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

但现在只有一半的控件背景色是透明的。

例如:

Label1 是透明的

label2 不是

button1 不是

button2 是透明的

我做错了什么?

最佳答案

试试这个:

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

Application.DoEvents();

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

关于c# - tabpage中的foreach控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33164696/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com