การรับส่งค่าผ่าน properties get set
Form A
private void Seach_Click(object sender, EventArgs e) { Form1 form = new Form1(); if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (form.IDstudent.Length > 0) { this.txtIDstudent.Text = form.IDstudent; } } }
FORM B
private string _student=""; DataGridViewRow dgRow = dgvStudent.CurrentRow; if (dgRow == null) { this.IDstudent= ""; return; } else { this.IDstudent = dgRow.Cells["IDstudent"].Value.ToString(); this.DialogResult = DialogResult.OK; }
properties
public string IDstudent { get { return this._student; } set { this._student = value; } }