C# 从自定义对话框中获取DialogResult
我有一些定制的对话框,上面有设置按钮,当我从C# 从自定义对话框中获取DialogResult,c#,.net,winforms,C#,.net,Winforms,我有一些定制的对话框,上面有设置按钮,当我从newBlockForm.ShowDialog(这个)退出时我需要它以在用户是否按下该按钮时获取对话框结果 就像在winforms对话框中一样 if(MessageBox.Show("Exit?", "Close UP", MessageBoxButtons.YesNo)== DialogResult.Yes) 知道我是怎么做的吗?您可以使用对话框窗体上按钮的属性并将其设置为: 然后以你的主要形式: //Create an instanc
newBlockForm.ShowDialog(这个)退出时我需要它
以在用户是否按下该按钮时获取对话框结果
就像在winforms对话框中一样
if(MessageBox.Show("Exit?", "Close UP",
MessageBoxButtons.YesNo)== DialogResult.Yes)
知道我是怎么做的吗?您可以使用对话框窗体上按钮的属性并将其设置为:
然后以你的主要形式:
//Create an instance of your dialog form
Form2 testDialog = new Form2();
// Show testDialog as a modal dialog and determine if DialogResult = OK.
if (testDialog.ShowDialog(this) == DialogResult.OK)
{
//do processing
}
else
{
//do processing
}
ShowDialog
方法本身返回一个DialogResult
,您可以通过设置表单设计器中相关按钮的DialogResult
来自动设置它。将表单上的AcceptButton
属性映射到设计器中的set
按钮
或者在设置按钮单击处理程序中,您可以设置一些值
private void HandleOnSetButtonClick(object sender, EventArgs e)
{
this.IsSetClicked = true;
this.Close();
//or
this.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
}
public Boolean IsSetClicked
{
get;
private set;
}
private void HandleOnSetButtonClick(object sender, EventArgs e)
{
this.IsSetClicked = true;
this.Close();
//or
this.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
}
public Boolean IsSetClicked
{
get;
private set;
}