本文整理汇总了C#中MessageBox.Add方法的典型用法代码示例。如果您正苦于以下问题:C# MessageBox.Add方法的具体用法?C# MessageBox.Add怎么用?C# MessageBox.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageBox
的用法示例。
在下文中一共展示了MessageBox.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddButtonsToForm
private static void AddButtonsToForm(MessageBox msgBoxFrm, MessageBoxButtons buttons)
{
// Rectangle screenRectangle = msgBoxFrm.RectangleToScreen(msgBoxFrm.ClientRectangle);
int titleHeight = 0;// screenRectangle.Top - msgBoxFrm.Top;
// var t = Type.GetType("Mono.Runtime");
// if ((t != null))
// titleHeight = 25;
switch (buttons)
{
case MessageBoxButtons.OK:
var but = new Button("OK");
but.MousePressedEvent += delegate { _state = DialogResult.OK; msgBoxFrm.Close(); };
msgBoxFrm.Add(but);
break;
case MessageBoxButtons.YesNo:
var butyes = new Button("Yes");
butyes.MousePressedEvent += delegate { _state = DialogResult.Yes; msgBoxFrm.Close(); };
msgBoxFrm.Add(butyes);
var butno = new Button("No");
butno.MousePressedEvent += delegate { _state = DialogResult.No; msgBoxFrm.Close(); };
msgBoxFrm.Add(butno);
break;
default:
throw new NotImplementedException("Only MessageBoxButtons.OK and YesNo supported at this time");
}
}
示例2: Show
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
{
if (text == null)
text = "";
if (caption == null)
caption = "";
MessageBox mymb = new MessageBox(caption);
mymb.mymb = mymb;
// ensure we are always in a known state
_state = DialogResult.None;
// convert to nice wrapped lines.
text = AddNewLinesToText(text);
// get pixel width and height
Graphics graphics = Graphics.FromImage(new Bitmap(1, 1));
SizeF textSize = graphics.MeasureString(text, SystemFonts.DefaultFont);
textSize = new SizeF(textSize.Width * 3, textSize.Height * 1);
// allow for icon
// if (icon != MessageBoxIcon.None)
// textSize.Width += SystemIcons.Question.Width;
mymb.Size = new AssortedWidgets.Util.Size(textSize.Width + 50, textSize.Height + 100);
//Rectangle screenRectangle = msgBoxFrm.RectangleToScreen(msgBoxFrm.ClientRectangle);
//int titleHeight = screenRectangle.Top - msgBoxFrm.Top;
var lblMessage = new Label(text);
var actualIcon = getMessageBoxIcon(icon);
if (actualIcon == null)
{
// lblMessage.Location = new Point(FORM_X_MARGIN, FORM_Y_MARGIN);
}
else
{
// var iconPbox = new PictureBox
{
// Image = actualIcon.ToBitmap(),
// Location = new Point(FORM_X_MARGIN, FORM_Y_MARGIN)
};
// msgBoxFrm.Controls.Add(iconPbox);
}
mymb.Add(lblMessage);
//mymb.Add(actualIcon);
AddButtonsToForm(mymb, buttons);
mymb.Pack();
DialogManager.Instance.SetModalDialog(mymb);
DialogResult answer = _state;
return answer;
}