您需要有一个属性才能将信息从辅助表单中提取出来。你仍然想使用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就有正确的想法。 –