我创建了一个用作InputBox的表单
public partial class InputBox : Form
{
public string sample
{
get
{ return TextBox1.Text; }
set
{ TextBox1.Text = value; }
}
public InputBox(string title, string question)
{
this.Text = title;
Label1.Text = question;
InitializeComponent();
}
}在我的另一种形式中,我称之为这个表格:
private void Button1_Click(object sender, EventArgs e)
{
InputBox dlg = new InputBox("TITLE", "Sample Question ?");
dlg.ShowDialog();
if (dlg.DialogResult == DialogResult.OK)
{
TextBox1.Text = dlg.sample;
}
}为什么我有NullReferenceException?Object reference not set to an instance of an object.
发布于 2013-08-25 07:54:57
如下所示
public InputBox(string title, string question)
{
InitializeComponent();
this.Text = title;
Label1.Text = question;
}首先初始化组件,然后可以设置属性
https://stackoverflow.com/questions/18426837
复制相似问题