gpt4 book ai didi

c# - 如何在运行时在 WinForm 中添加按钮?

转载 作者:行者123 更新时间:2023-11-30 13:16:01 26 4
gpt4 key购买 nike

我有以下代码:

public GUIWevbDav()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
try
{
//My XML Loading and other Code Here

//Trying to add Buttons here
if (DisplayNameNodes.Count > 0)
{
for (int i = 0; i < DisplayNameNodes.Count; i++)
{
Button folderButton = new Button();
folderButton.Width = 150;
folderButton.Height = 70;
folderButton.ForeColor = Color.Black;
folderButton.Text = DisplayNameNodes[i].InnerText;

Now trying to do GUIWevbDav.Controls.Add
(unable to get GUIWevbDav.Controls method )

}
}

我不想在运行时创建表单,而是将动态创建的按钮添加到我当前的 Winform 即:GUIWevDav

谢谢

最佳答案

只需使用 this.Controls.Add(folderButton)this 是您的表单。

关于c# - 如何在运行时在 WinForm 中添加按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3163578/

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