我有主表单和FORM 2(这是一种模态表单)。当退出时,Form2值返回0
当我输入FORM 2时,会出现一个组合框,所选值将存储在一个类中。从那里,它工作正常,因为messagebox确认存储的值。
但是,当我退出FORM 2和回主要形式中的文本框以显示该值,该值现在返回0
FORM 2:
private void btnOK_BS__Spec_Click(object sender, EventArgs e)
{
BSIT bsit = new BSIT();
string spec = cboIT_Spec.Text;
do
{
if (spec == "Animation and Game Development" || spec == "Digital Arts")
{
bsit.setSpec(spec);
MessageBox.Show("You chose " + bsit.getSpec() + ".", "Specialization",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Please select your Specialization.");
}
}
while (bsit.getSpec() == "");
}
CLASS
public class BSIT : Student
{
public BSIT()
{
spec = "";
}
private string spec;
public void setSpec(string spec)
{
if (spec == "Animation and Game Development" || spec == "Digital Arts")
{
this.spec = spec;
}
}
public string getSpec()
{
return spec;
}
}
主要形式(显示规格值)
private void txbxSpec_Input_TextChanged(object sender, EventArgs e)
{
BSIT bsit = new BSIT();
if (!(bsit.getSpec() == ""))
{
txbxSpec_Input.Text = bsit.getSpec();
}
}