将一个对象传递给Windows窗体的eventandler
本文关键字:窗体 eventandler Windows 一个对象 | 更新日期: 2023-09-27 18:11:58
我已经搜索了几个小时,但我似乎找不到答案。我觉得好像有一个简单的答案,我只是把头撞在墙上试图找到它。
private void Form1_Load(object sender, EventArgs e)
{
......bunch of code here...
GroupBoxController GBControl = new GroupBoxController(groupbox1);
}
private void nextbutton_Click(object sender, EventArgs e)
{
.....I want to be able to access GBControl and modify in here ..........
}
谢谢你的任何可能解决这个问题的答案。
private GroupBoxController GBControl;
private void Form1_Load(object sender, EventArgs e)
{
......bunch of code here...
GBControl = new GroupBoxController(groupbox1);
}
private void nextbutton_Click(object sender, EventArgs e)
{
GBControl.Whatever();
}
试试上面的
一般的想法是GBControl现在在类的所有成员的作用域中。在您将其作为Form_Load事件处理程序中的局部变量之前,这使得它在函数外部无法访问。