我有 MAIN FORM 和 FORM 2(这是一种模态形式)。
当我输入 FORM 2 时,有一个组合框,选择的值将存储在一个类中。从那里开始,它工作正常,因为消息框确认该值已存储。
但是当我退出 FORM 2 并返回到 MAIN FORM 以在文本框中显示该值时,该值现在返回 0。
表格 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() == "");
}
班级
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;
}
}
MAIN FORM(显示规格值)
private void txbxSpec_Input_TextChanged(object sender, EventArgs e)
{
BSIT bsit = new BSIT();
if (!(bsit.getSpec() == ""))
{
txbxSpec_Input.Text = bsit.getSpec();
}
}