使用DevComponents.DotNetBar2.dll
messagebox样式不能满足当前的要求,所以就把消息框使用了窗体自定义
样式展示
窗体的具体代码
public partial class FormMessageBox : Office2007Form { public DialogResult UserChoice { get; private set; } public FormMessageBox() { this.EnableGlass = false;//关键 InitializeComponent(); } public static DialogResult Show(string message, string title = "", MessageBoxButtons buttons = MessageBoxButtons.OK) { FormMessageBox messageBox = new FormMessageBox(); messageBox.lblMessage.Text = message; messageBox.Text = title; // 设置按钮 DialogResult result = DialogResult.None; switch (buttons) { case MessageBoxButtons.OK: messageBox.btnCancel.Visible = false; messageBox.btnOK.Text = "确定"; break; case MessageBoxButtons.OKCancel: messageBox.btnCancel.Text = "取消"; messageBox.btnOK.Text = "确定"; break; case MessageBoxButtons.YesNo: messageBox.btnCancel.Text = "取消"; messageBox.btnOK.Text = "确定"; break; case MessageBoxButtons.YesNoCancel: messageBox.btnCancel.Text = "取消"; messageBox.btnOK.Text = "确定"; break; } // 居中显示消息框 messageBox.StartPosition = FormStartPosition.CenterScreen; result = messageBox.ShowDialog(); return result; } private void btnOK_Click(object sender, EventArgs e) { UserChoice = DialogResult.OK; this.DialogResult = DialogResult.OK; } private void btnCancel_Click(object sender, EventArgs e) { UserChoice = DialogResult.Cancel; this.DialogResult = DialogResult.Cancel; } }
在窗体种如果只是单纯的提示 可以直接引用调用
FormMessageBox.Show("消息框的内容", "信息框", MessageBoxButtons.OK);
如果在窗体中弹出对话框,并且需要判断点击的是确定 还是取消 来执行相对应的代码则可以使用
DialogResult result = FormMessageBox.Show("This is a custom message.", "Custom Box", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { // 用户点击了“是”按钮,执行相应的操作 // ... } else if (result == DialogResult.No) { // 用户点击了“否”按钮,执行相应的操作 // ... } else if (result == DialogResult.Cancel) { // 用户点击了“取消”按钮,执行相应的操作 // ... }
下面是展示效果
标签:messageBox,自定义,c#,Text,BPM,DialogResult,result,FormMessageBox,MessageBoxButtons From: https://www.cnblogs.com/cxyyn/p/17742634.html