messagebox.show的返回值就是一个DialogResult参考该事例代码如下:private void validateUserEntry2() { // Checks the value of the text. if(serverName.Text.Length == 0) { // Initializes the variables to pass to the MessageBox.Show method. string message = "You did not enter a server name. Cancel this operation?"; string caption = "No Server Name Specified"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult result; // Displays the MessageBox. result = MessageBox.Show(this, message, caption, buttons, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign); if(result == DialogResult.Yes)//这里就是在判断返回值 { // Closes the parent form. this.Close(); } } }
{ // Checks the value of the text. if(serverName.Text.Length == 0)
{ // Initializes the variables to pass to the MessageBox.Show method. string message = "You did not enter a server name. Cancel this operation?";
string caption = "No Server Name Specified";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result; // Displays the MessageBox. result = MessageBox.Show(this, message, caption, buttons,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,
MessageBoxOptions.RightAlign); if(result == DialogResult.Yes)//这里就是在判断返回值
{ // Closes the parent form. this.Close(); } } }
public new string ShowDialog()
{
base.ShowDialog();
return "hello";
}
如果倒了,那说明,头脑病了,建议去看医生.最近的天气不怎么好,要多注意身体.闲话不多谈.好象上面没有人在和你讨论DialogResult枚举,一切用show或showDialog返回的值都是DialogResult即便是自定义的对话框,调用的也是show或showDialog方法,其返回值也必然是DialogResult建议多看看MSDN.另:以上是我的答复,是否也依然是答非所问呢?如果想返回自己的值想是什么就是什么如:public new type ShowDialog()
{
base.ShowDialog();
return type;
}type可以是任何类型,包括你自己定义的任意类型.这是不是你想要的?