我创建了一个用作 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.