您需要有一個屬性才能將信息從輔助表單中提取出來。你仍然想使用ShowDialog(),然後你可以檢查對話框的結果。這是來自內存,所以代碼可能不會構建,但應該給你這個想法。
在你的窗體2
public string Text
{
get { return this.SomeTextBoxOnTheForm.Text; }
set { this.SomeTextBoxOnTheForm.Text = value; }
}
//called from your "Save" button.
public void Save()
{
this.DialogResult = DialogResult.Ok;
this.Close();
}
//called from either your "DontSave" button or your "Cancel" button.
public void Cancel()
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
在你的其他Form1中
public void ShowForm2()
{
var form = new Form2();
//you could even set default text here
form.Text = "Enter a message...";
var result = form.ShowDialog();
if(result == DialogResult.Ok)
{
var finalText = form.Text;
//do something with the text
}
}
使用'的ShowDialog()'和評估返回 – Plutonix
請解釋一下你的意思是「得到他們按下按鈕的信息」。你想獲得什麼信息?如果確定用戶是否點擊是或否,那麼Plutonix就有正確的想法。 –