0
我已经搜索了几个小时,但我似乎无法找到答案。我感觉好像有一个简单的答案,我只是将我的头撞到墙上试图找到它。传递一个对象到Windows窗体EventHandler
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 ..........
}
谢谢任何可能解决这个问题的答案。
如果你想从'nextButton_Click'访问'GBControl',那么你为什么要在*** Form1_Load中声明并分配它? –
使'GBControl'成为窗体类的字段,而不是Load方法的局部变量。 – Blorgbeard
范围是你的问题在这里。了解变量的范围。 @TGH通过使'GBControl'的作用域更广泛的定义来解决这个问题,所以这两种方法都可以访问它。 – paqogomez