gpt4 book ai didi

C# 按钮可见性问题

转载 作者:太空宇宙 更新时间:2023-11-03 21:44:37 25 4
gpt4 key购买 nike

我已经以编程方式向 C# 窗体添加了几个按钮,但只有我通过设计器添加的按钮才真正显示出来。尽管如此,其余的仍然不可见。在此之前我正在执行很多操作;这可能是原因吗?

public FormView
{
List<Button> listOfButtons = new List<Button>();
int frame = 0;
for (int i = 0; i < 36; i++)
{
listOfButtons.Add(new Button());
}
listOfButtons[4 * frame].Width = 92;
listOfButtons[4 * frame].Height = 92;
listOfButtons[4 * frame].BackColor = Color.Red;
listOfButtons[4 * frame].BackgroundImage = System.Drawing.Image.FromFile("image.png");
listOfButtons[4 * frame].BackgroundImageLayout = ImageLayout.Stretch;
listOfButtons[4 * frame].ImageAlign = ContentAlignment.MiddleCenter;
listOfButtons[4 * frame].TextAlign = ContentAlignment.TopCenter;
listOfButtons[4 * frame].Location = new Point(1, 0);
listOfButtons[4 * frame].Click += new EventHandler(this.button1_Click);

listOfButtons[4 * frame + 1].Width = 92;
listOfButtons[4 * frame + 1].Height = 92;
listOfButtons[4 * frame + 1].BackColor = Color.Red;
listOfButtons[4 * frame + 1].BackgroundImage = System.Drawing.Image.FromFile("image.png");
listOfButtons[4 * frame + 1].BackgroundImageLayout = ImageLayout.Stretch;
listOfButtons[4 * frame + 1].ImageAlign = ContentAlignment.MiddleCenter;
listOfButtons[4 * frame + 1].TextAlign = ContentAlignment.TopCenter;
listOfButtons[4 * frame + 1].Location = new Point(1, 99);
listOfButtons[4 * frame + 1].Click += new EventHandler(this.button2_Click);

listOfButtons[4 * frame + 2].Width = 92;
listOfButtons[4 * frame + 2].Height = 92;
listOfButtons[4 * frame + 2].BackColor = Color.Red;
listOfButtons[4 * frame + 2].BackgroundImage = System.Drawing.Image.FromFile("image.png");
listOfButtons[4 * frame + 2].BackgroundImageLayout = ImageLayout.Stretch;
listOfButtons[4 * frame + 2].ImageAlign = ContentAlignment.MiddleCenter;
listOfButtons[4 * frame + 2].TextAlign = ContentAlignment.TopCenter;
listOfButtons[4 * frame + 2].Location = new Point(99, 0);
listOfButtons[4 * frame + 2].Click += new EventHandler(this.button3_Click);

listOfButtons[4 * frame + 3].Width = 92;
listOfButtons[4 * frame + 3].Height = 92;
listOfButtons[4 * frame + 3].BackColor = Color.Red;
listOfButtons[4 * frame + 3].BackgroundImage = System.Drawing.Image.FromFile("image.png");
listOfButtons[4 * frame + 3].BackgroundImageLayout = ImageLayout.Stretch;
listOfButtons[4 * frame + 3].ImageAlign = ContentAlignment.MiddleCenter;
listOfButtons[4 * frame + 3].TextAlign = ContentAlignment.TopCenter;
listOfButtons[4 * frame + 3].Location = new Point(99, 99);
listOfButtons[4 * frame + 3].Click += new EventHandler(this.button4_Click);


listOfButtons[4 * frame].Visible = true;
listOfButtons[4 * frame + 1].Visible = true;
listOfButtons[4 * frame + 2].Visible = true;
listOfButtons[4 * frame + 3].Visible = true;
InitializeComponent();
}

有什么想法吗?

最佳答案

我没有看到您将按钮添加到任何父控件。你应该做这样的事情......

Form1.Controls.Add(listOfButtons[4 * frame]); // and so on...

关于C# 按钮可见性问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17684116/

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