怎么对dialog进行操作??

eyestrong 2002-12-12 02:16:02
我 show 了一个 MessageBox,里面有 ok 和 cancel 的按钮,
怎样对这个对话框的两个按钮进行操作编程呢??
...全文
53 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenxy2002 2002-12-12
  • 打赏
  • 举报
回复
Msg="您是否要更改?";
if(MessageBox.Show(this,Msg,"是否更改?",System.Windows.Forms.MessageBoxButtons.YesNo,System.Windows.Forms.MessageBoxIcon.Question)== DialogResult.Yes)
{
if(!this.UpdateArea())
MessageBox.Show(this,"更改失败!","错误",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Error);
}
eyestrong 2002-12-12
  • 打赏
  • 举报
回复
谢谢班门斧大哥!
TheAres 2002-12-12
  • 打赏
  • 举报
回复
判断返回是DialogResult.OK,还是DailogResult.Cancel.
比如下面的简单例子:

string message = "You did not enter a server name. Cancel this operation?";
string caption = "No Server Name Specified";
MessageBoxButtons buttons = MessageBoxButtons.OKCancel;
DialogResult result;

// Displays the MessageBox.

result = MessageBox.Show(this, message, caption, buttons,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,
MessageBoxOptions.RightAlign);

if(result == DialogResult.OK)//or DailogResult.Cancel
{

// Closes the parent form.

this.Close();

}

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧