![](/img/trans.png)
[英]How can I make the randomString answer public so i can access it from another class
[英]How can I make dynamic buttons from another class?
我正在尝试组织我的项目,但是遇到一个问题,我无法向MainForm
动态添加按钮。 我如何做到这一点而又不会出错并且仍然让MainForm
优先启动而不是其他类?
public class anotherClass
{
public void AddButton(Form form)
{
Button b = new Button() { Text = "Dynamic Button", Width = 200 };
form.Controls.Add(b);
}
}
public class MyForm
{
anotherClass obj = new anotherClass();
obj.AddButton(this);
}
像这样的东西:
private void Form1_Load(object sender, EventArgs e)
{
Button b = new Button() { Text = "Dynamic Button", Width = 200 };
this.Controls.Add(b);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.