/// <summary> /// Shows a message in the UI of the specified type. /// </summary> /// <param name="text">The contents in the message box</param> /// <param name="caption">The title of the box</param> /// <param name="boxButton">The type of the buttons available</param> /// <param name="boxIcon">The icon of the box</param> /// <returns></returns> public DialogResult Message(string text, string caption, MessageBoxButtons boxButton, MessageBoxIcon boxIcon) { DialogResult result = new DialogResult(); if (boxButton.Equals(MessageBoxButtons.OK) && boxIcon.Equals(MessageBoxIcon.Error)) { result = MessageBox.Show(text, caption, boxButton, boxIcon); } if (boxButton.Equals(MessageBoxButtons.YesNo) && boxIcon.Equals(MessageBoxIcon.Warning)) { result = MessageBox.Show(text, caption, boxButton, boxIcon); } if (boxButton.Equals(MessageBoxButtons.OK) && boxIcon.Equals(MessageBoxIcon.Information)) { result = MessageBox.Show(text, caption, boxButton, boxIcon); } if (boxButton.Equals(MessageBoxButtons.YesNoCancel) && boxIcon.Equals(MessageBoxIcon.Warning)) { result = MessageBox.Show(text, caption, boxButton, boxIcon); } return(result); }
private static string GetSwingIcon(MessageBoxIcon icon) { string swingIcon = string.Empty; if (icon.Equals(MessageBoxIcon.None)) { swingIcon = "checkmark"; } else if (icon.Equals(MessageBoxIcon.Hand)) { swingIcon = "stop"; } else if (icon.Equals(MessageBoxIcon.Question)) { swingIcon = "question"; } else if (icon.Equals(MessageBoxIcon.Exclamation)) { swingIcon = "warn"; } else if (icon.Equals(MessageBoxIcon.Asterisk)) { swingIcon = "wizard"; } else if (icon.Equals(MessageBoxIcon.Stop)) { swingIcon = "noaccess"; } else if (icon.Equals(MessageBoxIcon.Error)) { swingIcon = "stop"; } else if (icon.Equals(MessageBoxIcon.Warning)) { swingIcon = "nuke"; } else if (icon.Equals(MessageBoxIcon.Information)) { swingIcon = "info"; } else { swingIcon = "info"; } return(swingIcon); }
private void message_box_frm_load(global::System.Object sender, System.EventArgs e) { resources = new ResourceManager(GetType().Namespace + ".strings", Assembly.GetExecutingAssembly()); SuspendLayout(); title.Text = titleMsg; var fontToMeasure = new Font(enVars.layoutDesign.fontTitle.Families[0], enVars.layoutDesign.DialogTitleFontSize, System.Drawing.FontStyle.Regular); SizeF sizeOfString = new SizeF(); sizeOfString = TextRenderer.MeasureText(titleMsg, fontToMeasure); title.Location = new Point(Convert.ToInt32(this.Width / 2 - sizeOfString.Width / 2), this.title.Location.Y); fontToMeasure = new Font(enVars.layoutDesign.fontTitle.Families[0], enVars.layoutDesign.RegularTextFontSize, System.Drawing.FontStyle.Regular); sizeOfString = TextRenderer.MeasureText("_", fontToMeasure); message.Text = messageText; int numLines = Convert.ToInt32(this.messageText.Length / (this.message.Width / sizeOfString.Width)) + 1; this.message.Height = Convert.ToInt32(numLines * sizeOfString.Height); if (iconImage.Equals(MessageBoxIcon.Information)) { try { iconBox.Image = Image.FromFile(enVars.imagesPath + Convert.ToString("information.png")); } catch (Exception ex) { } } else if (iconImage.Equals(MessageBoxIcon.Question)) { try { iconBox.Image = Image.FromFile(enVars.imagesPath + Convert.ToString("question.png")); } catch (Exception ex) { } } else if (iconImage.Equals(MessageBoxIcon.Warning)) { try { iconBox.Image = Image.FromFile(enVars.imagesPath + Convert.ToString("warning.png")); } catch (Exception ex) { } } else if (iconImage.Equals(MessageBoxIcon.Exclamation)) { try { iconBox.Image = Image.FromFile(enVars.imagesPath + Convert.ToString("exclamation.png")); } catch (Exception ex) { } } else if (iconImage.Equals(MessageBoxIcon.Error)) { try { iconBox.Image = Image.FromFile(enVars.imagesPath + Convert.ToString("error.png")); } catch (Exception ex) { } } iconBox.SizeMode = PictureBoxSizeMode.StretchImage; System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(enVars.currentLang); if (buttons.Equals(MessageBoxButtons.OK)) { ContinueBtn.Visible = true; cancelBtn.Visible = false; ContinueBtn.Location = new Point(Convert.ToInt32(this.Width / 2 - this.ContinueBtn.Width / 2), this.ContinueBtn.Location.Y); } else if (buttons.Equals(MessageBoxButtons.OKCancel)) { ContinueBtn.Text = resources.GetString("ok"); ContinueBtn.Visible = true; cancelBtn.Text = resources.GetString("cancel"); cancelBtn.Visible = true; } else if (buttons.Equals(MessageBoxButtons.YesNo)) { ContinueBtn.Text = resources.GetString("yes"); ContinueBtn.Visible = true; cancelBtn.Text = resources.GetString("no"); cancelBtn.Visible = true; } else if (buttons.Equals(MessageBoxButtons.RetryCancel)) { ContinueBtn.Text = resources.GetString("retry"); ContinueBtn.Visible = true; cancelBtn.Text = resources.GetString("cancel"); cancelBtn.Visible = true; } ResumeLayout(); Refresh(); }