我想将我的表单作为引用传递给一个类,这样类对象就可以从表单访问公共方法。我已经在几个不同的地方尝试过,但每个地方都有一些限制。
有没有办法从事件外部实例化类,但仍以形式传递?
namespace MyApplication
{
public partial class Form1 : Form
{
//If I instantiate the class here, the form seemingly doesn't exist yet
//and can't be passed in using "this."
Downloader downloader = new Downloader(this);
private void Form1_Load(object sender, EventArgs e)
{
//If I instantiate the class here, the form can be passed in, but the
//class object can't be seen outside of this event.
Downloader downloader = new Downloader(this);
}
private void downloadButton_Click(object sender, EventArgs e)
{
//If I instantiate the class here, the form can be passed in, but the
//class object can't be seen outside of this event.
Downloader downloader = new Downloader(this);
downloader.dostuff();
}
}
}