我想创建一个对话框结果消息框,并在按钮上带有我自己指定的标签。我知道使用"是否"选项按钮对 DR 消息框进行编码。
创建自己的对话框和放置按钮。您可以为按钮分配对话框结果值。
this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;
this.button2.DialogResult = System.Windows.Forms.DialogResult.No;
您可以尝试使用自己的自定义按钮和图标以及要显示的标签制作自定义消息框。创建构造函数,如下所示。添加属性显示数据以存储要显示的消息框数据。
public void CustomMessage(string title, string dataTodisplay, string leftButton, string rightButton, MessageBoxIcon iconSet)
{
// Set up some properties.
this.Font = SystemFonts.MessageBoxFont;
this.ForeColor = SystemColors.WindowText;
InitializeComponent();
DisplayData = dataTodisplay;
// Do some measurements with Graphics.
SetFormData(dataTodisplay);
// Set the title, and some Text properties.
if (string.IsNullOrEmpty(title) == false)
{
this.Text = title;
}
// Set the left button, which is optional.
if (string.IsNullOrEmpty(leftButton) == false)
{
this.ButtonOK.Text = leftButton;
}
Else
{
this.AcceptButton = ButtonCancel
this.ButtonCancel.Visible = False
}
// Set the PictureBox and the icon.
if ((iconSet != null))
{
ShowMessageBoxIcon(iconSet);
}
在此处将图标分配给图片框
private void ShowMessageBoxIcon(MessageBoxIcon iconSet)
{
switch (iconSet)
{
case MessageBoxIcon.Asterisk:
PictureBoxIconImage.Image = Bitmap.FromHicon(SystemIcons.Asterisk.Handle);
break;
case MessageBoxIcon.Error:
PictureBoxIconImage.Image = Bitmap.FromHicon(SystemIcons.Error.Handle);
/*
* Add remaining icons here
*
*/
}
}
this.ButtonCancel.Text = rightButton
}