如何从另一个类调用FORM类中的方法,但是两者都是相同的名称空间 [英] How to call a method in FORM class from another class but both are same namespace
本文介绍了如何从另一个类调用FORM类中的方法,但是两者都是相同的名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class Form1 : Form
{
public void enable()
{
//1st method which i want to call from another class
}
public void display()
{
//2nd method which i want to call from another class
}
}
class Buffer : signal
{
protected override Analyse()
{
//from here i want to call two functions in form class
}
}
这是我的代码看起来像任何人的样子,请回复此提示.........
this is how my code looks like anyone please reply this tread.........
推荐答案
在创建Buffer类时,您必须将引用传递给Form1的真实实例,然后才使用该实例.示例代码:
When creating the Buffer class, you have to pass reference to the real instance of Form1 then just use that instance. Sample code:
class Form1 : Form
{
public void InitBuffer()
{
Buffer b = new Buffer(this);
...
}
public void enable()
{
//1st method which i want to call from another class
}
public void display()
{
//2nd method which i want to call from another class
}
}
class Buffer : signal
{
private Form1 form;
public Buffer(Form1 parent)
{
form = parent;
}
protected override Analyse()
{
form.enable();
form.display();
}
}
您无法一无所获地获取Form1的真实实例.
You can't grab the true instance of Form1 just like that out of nowhere.
这篇关于如何从另一个类调用FORM类中的方法,但是两者都是相同的名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文