我有主表單和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();
}
}