www.pudn.com > Fetion.rar > ImpsMessageBox.cs
namespace Imps.Client.Pc
{
using Imps.Client.Pc.BizControls;
using Imps.Client.Pc.Controls;
using Imps.Client.Resource;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
public class ImpsMessageBox : XIMDialog
{
private MessageBoxButtons _btns;
private MessageBoxDefaultButton _defaultBtn;
private XButton btnA;
private XButton btnB;
private XButton btnC;
private IContainer components;
private XLabel lbMessage;
private PictureBox pbIcon;
private Panel pnlContainer;
public ImpsMessageBox(IWin32Window wnd, string details, MessageBoxButtons btns, MessageBoxIcon icon) : this(wnd, details, btns, icon, MessageBoxDefaultButton.Button1)
{
}
public ImpsMessageBox(IWin32Window wnd, string details, MessageBoxButtons btns, MessageBoxIcon icon, MessageBoxDefaultButton defaultBtn)
{
this._btns = btns;
this._defaultBtn = defaultBtn;
this.InitializeComponent();
this.InitButtons();
this.InitIcon(icon);
this.LoadResource(details);
this.AdjustControlPosition();
this.initComponentRegion();
}
private void AdjustButtonsLocation()
{
Button[] buttonArray = new Button[] { this.btnA, this.btnB, this.btnC };
Size size = this.btnA.Size;
int num = 10;
int num2 = 0;
int num3 = 0;
foreach (Button button in buttonArray)
{
if (button.Text.Length > 0)
{
num3 += size.Width;
if (num2 > 0)
{
num3 += num;
}
num2++;
}
}
int num4 = ((this.pnlContainer.Width - num3) / 2) + this.pnlContainer.Left;
foreach (Button button2 in buttonArray)
{
if (button2.Text.Length > 0)
{
button2.Left = num4;
num4 += size.Width + num;
}
}
}
private void AdjustControlPosition()
{
int num2;
Size size = new Size(250, 0x7e);
this.pnlContainer.MinimumSize = size;
Size size2 = this.lbMessage.Size;
if (size.Height < (size2.Height + 40))
{
size.Height = size2.Height + 40;
}
bool flag = this.pbIcon.Image != null;
int x = 0x18;
if (flag)
{
this.pbIcon.Location = new System.Drawing.Point(x, (size.Height - this.pbIcon.Height) / 2);
num2 = this.pbIcon.Right + 20;
size.Width = (num2 + size2.Width) + 20;
}
else
{
if (size.Width < ((size2.Width + x) + x))
{
size.Width = (size2.Width + x) + x;
}
num2 = (size.Width - size2.Width) / 2;
}
int y = (size.Height - size2.Height) / 2;
this.lbMessage.Location = new System.Drawing.Point(num2, y);
this.pnlContainer.Size = size;
}
private void btn_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && (e.KeyCode == Keys.C))
{
Clipboard.SetText(this.lbMessage.Text);
}
}
private void btnA_Click(object sender, EventArgs e)
{
switch (this._btns)
{
case MessageBoxButtons.OK:
case MessageBoxButtons.OKCancel:
base.DialogResult = DialogResult.OK;
break;
case MessageBoxButtons.AbortRetryIgnore:
base.DialogResult = DialogResult.Abort;
break;
case MessageBoxButtons.YesNoCancel:
case MessageBoxButtons.YesNo:
base.DialogResult = DialogResult.Yes;
break;
case MessageBoxButtons.RetryCancel:
base.DialogResult = DialogResult.Retry;
break;
}
base.Close();
}
private void btnB_Click(object sender, EventArgs e)
{
switch (this._btns)
{
case MessageBoxButtons.OKCancel:
case MessageBoxButtons.RetryCancel:
base.DialogResult = DialogResult.Cancel;
break;
case MessageBoxButtons.AbortRetryIgnore:
base.DialogResult = DialogResult.Retry;
break;
case MessageBoxButtons.YesNoCancel:
case MessageBoxButtons.YesNo:
base.DialogResult = DialogResult.No;
break;
}
base.Close();
}
private void btnC_Click(object sender, EventArgs e)
{
switch (this._btns)
{
case MessageBoxButtons.AbortRetryIgnore:
base.DialogResult = DialogResult.Ignore;
break;
case MessageBoxButtons.YesNoCancel:
base.DialogResult = DialogResult.Cancel;
break;
}
base.Close();
}
protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private void ImpsMessageBox_Shown(object sender, EventArgs e)
{
switch (this._defaultBtn)
{
case MessageBoxDefaultButton.Button1:
this.btnA.Focus();
break;
case MessageBoxDefaultButton.Button2:
this.btnB.Focus();
break;
case MessageBoxDefaultButton.Button3:
this.btnC.Focus();
break;
}
base.KeyDown += new KeyEventHandler(this.btn_KeyDown);
this.AdjustButtonsLocation();
base.SizeChanged += new EventHandler(this.ImpsMessageBox_SizeChanged);
}
private void ImpsMessageBox_SizeChanged(object sender, EventArgs e)
{
this.AdjustButtonsLocation();
}
private void InitButtons()
{
switch (this._btns)
{
case MessageBoxButtons.OK:
this.SetBtnText(StringTable.DialogButton.btnOk, string.Empty, string.Empty);
base.AcceptButton = this.btnA;
base.CancelButton = this.btnA;
break;
case MessageBoxButtons.OKCancel:
this.SetBtnText(StringTable.DialogButton.btnOk, StringTable.DialogButton.btnCancel, string.Empty);
base.AcceptButton = this.btnA;
base.CancelButton = this.btnB;
break;
case MessageBoxButtons.AbortRetryIgnore:
this.SetBtnText(StringTable.DialogButton.btnCancel, StringTable.DialogButton.btnRetry, StringTable.DialogButton.btnCancel);
base.AcceptButton = this.btnA;
base.CancelButton = this.btnC;
break;
case MessageBoxButtons.YesNoCancel:
this.SetBtnText(StringTable.DialogButton.btnYes, StringTable.DialogButton.btnNo, StringTable.DialogButton.btnCancel);
base.AcceptButton = this.btnA;
base.CancelButton = this.btnC;
break;
case MessageBoxButtons.YesNo:
this.SetBtnText(StringTable.DialogButton.btnYes, StringTable.DialogButton.btnNo, string.Empty);
base.AcceptButton = this.btnA;
base.CancelButton = this.btnB;
break;
case MessageBoxButtons.RetryCancel:
this.SetBtnText(StringTable.DialogButton.btnRetry, StringTable.DialogButton.btnCancel, string.Empty);
base.AcceptButton = this.btnA;
base.CancelButton = this.btnB;
break;
}
MessageBoxDefaultButton button = this._defaultBtn;
if (button != MessageBoxDefaultButton.Button1)
{
if (button != MessageBoxDefaultButton.Button2)
{
if (button == MessageBoxDefaultButton.Button3)
{
base.AcceptButton = this.btnC;
}
return;
}
}
else
{
base.AcceptButton = this.btnA;
return;
}
base.AcceptButton = this.btnB;
}
private void InitializeComponent()
{
this.pnlContainer = new Panel();
this.pbIcon = new PictureBox();
this.lbMessage = new XLabel();
this.btnC = new XButton();
this.btnB = new XButton();
this.btnA = new XButton();
this.pnlContainer.SuspendLayout();
((ISupportInitialize) this.pbIcon).BeginInit();
base.SuspendLayout();
this.pnlContainer.BackColor = Color.Transparent;
this.pnlContainer.Controls.Add(this.pbIcon);
this.pnlContainer.Controls.Add(this.lbMessage);
this.pnlContainer.Location = new System.Drawing.Point(3, 0);
this.pnlContainer.Name = "pnlContainer";
this.pnlContainer.Size = new Size(240, 0x40);
this.pnlContainer.TabIndex = 2;
this.pbIcon.ErrorImage = null;
this.pbIcon.InitialImage = null;
this.pbIcon.Location = new System.Drawing.Point(3, 3);
this.pbIcon.Name = "pbIcon";
this.pbIcon.Size = new Size(100, 50);
this.pbIcon.SizeMode = PictureBoxSizeMode.AutoSize;
this.pbIcon.TabIndex = 4;
this.pbIcon.TabStop = false;
this.pbIcon.Visible = false;
this.lbMessage.AutoSize = true;
this.lbMessage.BorderColor = Color.Empty;
this.lbMessage.ButtonBorderStyle = ButtonBorderStyle.None;
this.lbMessage.Location = new System.Drawing.Point(0x3a, 11);
this.lbMessage.Name = "lbMessage";
this.lbMessage.Size = new Size(0, 13);
this.lbMessage.TabIndex = 3;
this.lbMessage.UseMnemonic = false;
this.btnC.Anchor = AnchorStyles.Top;
this.btnC.AutoArrangementX = true;
this.btnC.AutoSizeToImage = false;
this.btnC.BackColor = Color.Transparent;
this.btnC.BackgroundImageDisable = null;
this.btnC.BackgroundImageDown = null;
this.btnC.BackgroundImageHover = null;
this.btnC.ChangeSkin = true;
this.btnC.Location = new System.Drawing.Point(0xae, 0x5c);
this.btnC.Name = "btnC";
this.btnC.Size = new Size(0x4b, 0x19);
this.btnC.TabIndex = 2;
this.btnC.UseVisualStyleBackColor = false;
this.btnC.Click += new EventHandler(this.btnC_Click);
this.btnB.Anchor = AnchorStyles.Top;
this.btnB.AutoArrangementX = true;
this.btnB.AutoSizeToImage = false;
this.btnB.BackColor = Color.Transparent;
this.btnB.BackgroundImageDisable = null;
this.btnB.BackgroundImageDown = null;
this.btnB.BackgroundImageHover = null;
this.btnB.ChangeSkin = true;
this.btnB.Location = new System.Drawing.Point(0x5d, 0x5c);
this.btnB.Name = "btnB";
this.btnB.Size = new Size(0x4b, 0x19);
this.btnB.TabIndex = 1;
this.btnB.UseVisualStyleBackColor = false;
this.btnB.Click += new EventHandler(this.btnB_Click);
this.btnA.Anchor = AnchorStyles.Top;
this.btnA.AutoArrangementX = true;
this.btnA.AutoSizeToImage = false;
this.btnA.BackColor = Color.Transparent;
this.btnA.BackgroundImageDisable = null;
this.btnA.BackgroundImageDown = null;
this.btnA.BackgroundImageHover = null;
this.btnA.ChangeSkin = true;
this.btnA.Location = new System.Drawing.Point(12, 0x5c);
this.btnA.Name = "btnA";
this.btnA.Size = new Size(0x4b, 0x19);
this.btnA.TabIndex = 0;
this.btnA.UseVisualStyleBackColor = false;
this.btnA.Click += new EventHandler(this.btnA_Click);
base.AutoScaleDimensions = new SizeF(6f, 13f);
base.AutoScaleMode = AutoScaleMode.Font;
base.BaseHeight = 0xab;
base.BaseWidth = 0x115;
base.ClientSize = new Size(0x115, 0xab);
base.Controls.Add(this.pnlContainer);
base.Controls.Add(this.btnC);
base.Controls.Add(this.btnB);
base.Controls.Add(this.btnA);
base.DisplayLocation = new System.Drawing.Point(15, 15);
base.DisplaySize = new Size(0x115, 0xab);
base.KeyPreview = true;
base.Name = "ImpsMessageBox";
base.Padding = new Padding(6, 0x22, 0x13, 9);
base.ShowInTaskbar = false;
base.StartPosition = FormStartPosition.CenterScreen;
base.Text = "ImpsMessageBox";
base.Shown += new EventHandler(this.ImpsMessageBox_Shown);
this.pnlContainer.ResumeLayout(false);
this.pnlContainer.PerformLayout();
((ISupportInitialize) this.pbIcon).EndInit();
base.ResumeLayout(false);
}
private void InitIcon(MessageBoxIcon icon)
{
this.pbIcon.Visible = true;
switch (icon)
{
case MessageBoxIcon.Hand:
this.pbIcon.Image = ImpsIcons.InfoImage;
return;
case MessageBoxIcon.Question:
this.pbIcon.Image = ImpsIcons.InfoImage;
return;
case MessageBoxIcon.Exclamation:
this.pbIcon.Image = ImpsIcons.InfoImage;
return;
case MessageBoxIcon.Asterisk:
this.pbIcon.Image = ImpsIcons.InfoImage;
return;
}
this.pbIcon.Image = null;
this.pbIcon.Visible = false;
}
private void LoadResource(string details)
{
base.Text = AppDictionary.CurrentClientName;
base.MinimizeBox = false;
int num2 = Screen.PrimaryScreen.WorkingArea.Width / 2;
int num3 = 160;
TextFormatFlags noPrefix = TextFormatFlags.NoPrefix;
Size size = TextRenderer.MeasureText(details, this.lbMessage.Font, this.lbMessage.Size, noPrefix);
int num4 = (int) Math.Ceiling((double) (((double) size.Width) / ((double) num2)));
int width = size.Width + 10;
if (width < num3)
{
width = num3;
}
else if (width > num2)
{
width = num2;
}
this.lbMessage.AutoSize = false;
this.lbMessage.Size = new Size(width, num4 * (size.Height + 5));
this.lbMessage.Text = details;
}
private void SetBtnText(string strA, string strB, string strC)
{
this.btnA.Text = strA;
this.btnA.Visible = strA.Length > 0;
this.btnB.Text = strB;
this.btnB.Visible = strB.Length > 0;
this.btnC.Text = strC;
this.btnC.Visible = strC.Length > 0;
}
}
}