internal System.Windows.Forms.DialogResult ShowDialog(String messageID, params Object[] args) { try { SWDialogBox.MessageBoxIcon iconStyle = SWDialogBox.MessageBoxIcon.None; SWDialogBox.MessageBoxButton buttonStyle; System.Resources.ResourceManager rm = new System.Resources.ResourceManager("SWDialogBox.SWDialogBox", this.GetType().Assembly); try { //从资源包中获取指定消息编号的消息框风格类型 //如果指定的消息编号在资源包中没定义或定义的是一个无效的消息框风格,则捕获其异常。 iconStyle = (SWDialogBox.MessageBoxIcon)Int32.Parse(rm.GetString(messageID)); buttonStyle = (SWDialogBox.MessageBoxButton)Int32.Parse(rm.GetString(messageID)); } catch { //根据指定消息编号设置其消息框的风格类型 switch(messageID.Substring(0, 1)) { case CriticalFLAG: iconStyle = SWDialogBox.MessageBoxIcon.Critical; buttonStyle = SWDialogBox.MessageBoxButton.OK | SWDialogBox.MessageBoxButton.Detail; break; case QuestionFLAG: iconStyle = SWDialogBox.MessageBoxIcon.Question; buttonStyle = SWDialogBox.MessageBoxButton.YesNo | SWDialogBox.MessageBoxButton.Detail; break; case ExclamationFLAG: iconStyle = SWDialogBox.MessageBoxIcon.Exclamation; buttonStyle = SWDialogBox.MessageBoxButton.OK | SWDialogBox.MessageBoxButton.Detail; break; case InformationFLAG: iconStyle = SWDialogBox.MessageBoxIcon.Information; buttonStyle = SWDialogBox.MessageBoxButton.OK | SWDialogBox.MessageBoxButton.Detail; break; default: iconStyle = SWDialogBox.MessageBoxIcon.Information; buttonStyle = SWDialogBox.MessageBoxButton.OK | SWDialogBox.MessageBoxButton.Detail; break; } } if(messageID == "*999") { if(args == null) WriteLog(rm.GetString(messageID + CAPTIONSUFFIX), rm.GetString(messageID + DESCRIPTIONSUFFIX)); else WriteLog(String.Format(rm.GetString(messageID + CAPTIONSUFFIX), args), String.Format(rm.GetString(messageID + DESCRIPTIONSUFFIX), args)); } //从资源包中读取指定消息编号的文本内容 if(args == null) return this.ShowDialog(rm.GetString(messageID + MESSAGESUFFIX), rm.GetString(messageID + CAPTIONSUFFIX), rm.GetString(messageID + DESCRIPTIONSUFFIX), buttonStyle, iconStyle); else return this.ShowDialog(String.Format(rm.GetString(messageID + MESSAGESUFFIX), args), String.Format(rm.GetString(messageID + CAPTIONSUFFIX), args), String.Format(rm.GetString(messageID + DESCRIPTIONSUFFIX), args), buttonStyle, iconStyle); } catch { throw; } }
internal System.Windows.Forms.DialogResult ShowDialog(String message, String caption, String description, SWDialogBox.MessageBoxButton button, SWDialogBox.MessageBoxIcon icon) { try { String iconKey = null; System.Resources.ResourceManager rm = new System.Resources.ResourceManager("SWDialogBox.SWDialogBox", this.GetType().Assembly); //根据当前的消息编号得到其对应的消息类型(设置消息框图标类型) switch((icon & (SWDialogBox.MessageBoxIcon)ICONMASKWORD)) { case SWDialogBox.MessageBoxIcon.Critical: iconKey = "ICON-Critical"; break; case SWDialogBox.MessageBoxIcon.Question: iconKey = "ICON-Question"; break; case SWDialogBox.MessageBoxIcon.Exclamation: iconKey = "ICON-Exclamation"; break; case SWDialogBox.MessageBoxIcon.Information: iconKey = "ICON-Information"; break; } //装载消息框指示图标 if(iconKey != null && iconKey != String.Empty) this.MessageIcon.Image = ((System.Drawing.Icon)rm.GetObject(iconKey)).ToBitmap(); //装载消息框窗体图标 // if(this.Icon != null) // this.Icon = (System.Drawing.Icon)rm.GetObject("ICON-App"); //设置消息框中各个信息文本 this.Text = caption; lblMessage.Text = message; txtDescription.Text = description; //得到消息文本框的Graphics对象 Graphics g = lblMessage.CreateGraphics(); //得到将显示的消息文本的显示区域/大小 SizeF messageSize = new SizeF(); messageSize = g.MeasureString(lblMessage.Text, lblMessage.Font, lblMessage.Width); //设置消息文本框的高度 lblMessage.Height = (Int32)messageSize.Height; //设置按钮的位置 btnDetail.Top = lblMessage.Top + lblMessage.Height + 32; //设置消息框窗体的高度 this.ClientSize = new System.Drawing.Size(this.ClientSize.Width, btnDetail.Top + btnDetail.Height + 16); //创建消息框的按钮并排版消息框窗体界面 this.CreateButton(button); //打开模式对话框 return this.ShowDialog(); } catch { throw; } }
/// <summary> /// 显示具有指定文本、标题、详细注视、按钮、图标和默认按钮的消息框。 /// </summary> /// <param name="message">消息框中显示的文本。</param> /// <param name="caption">消息框的标题栏中显示的文本。</param> /// <param name="description">消息框的详细注视栏中显示的文本。</param> /// <param name="button">SWDialogBox.MessageBoxButton 值之一,它指定在消息框中显示哪些按钮及默认按钮。</param> /// <param name="icon">SWDialogBox.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。</param> /// <returns>System.Window.Forms.DialogResult 值之一。</returns> public static System.Windows.Forms.DialogResult Show(String message, String caption, String description, SWDialogBox.MessageBoxButton button, SWDialogBox.MessageBoxIcon icon) { SWDialogBox.FMessageBox messageForm = null; try { messageForm = new SWDialogBox.FMessageBox(); messageForm.Icon = moIcon; return(messageForm.ShowDialog(message, caption, description, button, icon)); } catch { throw; } finally { if (messageForm != null) { messageForm.Dispose(); } } }