从 class 更改文本时出现 NullReferenceException
NullReferenceException when changing text from class
我试图通过这样做将 TextBox
文本从另一个 class 更改为:
我的表格 1:
public void showLog(string s)
{
txtlog.Text = s;
}
和我的 class:
class Functions
{
private readonly Form1 form;
public Functions(Form1 form)
{
this.form = form;
}
public Functions()
{
}
private void FindDlLinks(string url)
{
// line bellow gave me a NullReferenceException error
form.showLog("something");
}
}
错误是:
Object reference not set to an instance of an object.
它与一个简单的 MessageBox
一起工作,但似乎我的 TextBox
.
有问题
在实例化 Functions
的实例时将 this
作为参数发送到 constructor
。像这样:
Functions fr = new Functions(this);
fr.FindDlLinks("");
我试图通过这样做将 TextBox
文本从另一个 class 更改为:
我的表格 1:
public void showLog(string s)
{
txtlog.Text = s;
}
和我的 class:
class Functions
{
private readonly Form1 form;
public Functions(Form1 form)
{
this.form = form;
}
public Functions()
{
}
private void FindDlLinks(string url)
{
// line bellow gave me a NullReferenceException error
form.showLog("something");
}
}
错误是:
Object reference not set to an instance of an object.
它与一个简单的 MessageBox
一起工作,但似乎我的 TextBox
.
在实例化 Functions
的实例时将 this
作为参数发送到 constructor
。像这样:
Functions fr = new Functions(this);
fr.FindDlLinks("");