123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace LYFZ.ComponentLibrary
- {
- public partial class frmMessageBox : LYFZ.ComponentLibrary.BaseFormSimple
- {
- Timer tempTimer;
- public bool bTimerUp = false;
- public int closeTimeSet = 1;
- public frmMessageBox()
- {
- InitializeComponent();
- this.btnExpandYes.Focus();
- this.btnAppFormExit.Click+=btnAppFormExit_Click2;
-
- }
- protected void btnAppFormExit_Click2(object sender, EventArgs e)
- {
- if (this.MsgBoxButtons == MessageBoxButtons.AbortRetryIgnore)
- { this.DialogResult = DialogResult.Ignore; }
- else if (this.MsgBoxButtons == MessageBoxButtons.OK)
- { this.DialogResult = DialogResult.OK; }
- else if (this.MsgBoxButtons == MessageBoxButtons.OKCancel)
- { this.DialogResult = DialogResult.Cancel; }
- else if (this.MsgBoxButtons == MessageBoxButtons.RetryCancel)
- { this.DialogResult = DialogResult.Cancel; }
- else if (this.MsgBoxButtons == MessageBoxButtons.YesNo)
- { this.DialogResult = DialogResult.No; }
- else if (this.MsgBoxButtons == MessageBoxButtons.YesNoCancel)
- { this.DialogResult = DialogResult.Cancel; }
- }
- MessageBoxButtons _MsgBoxButtons = MessageBoxButtons.OK;
- /// <summary>
- ///
- /// </summary>
- public MessageBoxButtons MsgBoxButtons
- {
- get { return _MsgBoxButtons; }
- set { _MsgBoxButtons = value; }
- }
- private void btnExpandOK_Click(object sender, EventArgs e)
- {
- if (this.btnExpandOK.Text == "否")
- {
- this.DialogResult = DialogResult.No;
- }
- else
- {
- this.DialogResult = DialogResult.OK;
- }
- this.Close();
- }
- private void btnExpandNo_Click(object sender, EventArgs e)
- {
- if (this.btnExpandNo.Text == "取消")
- {
- this.DialogResult = DialogResult.Cancel;
- }
- else
- {
- this.DialogResult = DialogResult.No;
- }
- this.Close();
- }
- private void btnExpandYes_Click(object sender, EventArgs e)
- {
- if (this.MsgBoxButtons == MessageBoxButtons.OKCancel)
- {
- this.DialogResult = DialogResult.OK;
- }
- else
- {
- this.DialogResult = DialogResult.Yes;
- }
- this.Close();
- }
- private void frmMessageBox_FormClosed(object sender, FormClosedEventArgs e)
- {
-
- }
- private void frmMessageBox_Load(object sender, EventArgs e)
- {
- switch (MsgBoxButtons)
- {
- case MessageBoxButtons.OK:
- this.btnExpandOK.Visible = true;
- this.btnExpandNo.Visible = false;
- this.btnExpandYes.Visible = false;
- break;
- case MessageBoxButtons.YesNo:
- this.btnExpandNo.Visible = true;
- this.btnExpandYes.Visible = true;
- this.btnExpandOK.Visible = false;
- break;
- case MessageBoxButtons.OKCancel:
- this.btnExpandNo.Visible = true;
- this.btnExpandYes.Visible = true;
- this.btnExpandOK.Visible = false;
- this.btnExpandYes.Text = "确定";
- this.btnExpandNo.Text = "取消";
- break;
- case MessageBoxButtons.YesNoCancel:
- this.btnExpandNo.Visible = true;
- this.btnExpandYes.Visible = true;
- this.btnExpandOK.Visible = true;
- this.btnExpandOK.Text = "否";
- this.btnExpandNo.Text = "取消";
- break;
- }
- SizeF size = this.CreateGraphics().MeasureString(this.lbMseValue.Text, this.lbMseValue.Font);
- if (Convert.ToInt32(size.Width) > this.Width - 10)
- {
- this.lbMseValue.TextAlign = ContentAlignment.MiddleLeft;
- }
- if (size.Width / this.Width > 3)
- {
- int tempHeight = (Convert.ToInt32(size.Width / this.Width) - 3) * 20;
- this.Height = this.Height + tempHeight;
-
- this.plContent.Height = this.plContent.Height + tempHeight;
- //this.btnExpandOK.Location = new Point(this.btnExpandOK.Location.X, this.btnExpandOK.Location.Y + tempHeight);
- SetButtonLocation(this.btnExpandOK,tempHeight);
- SetButtonLocation(this.btnExpandNo, tempHeight);
- SetButtonLocation(this.btnExpandYes, tempHeight);
- }
- if(bTimerUp)
- {
- tempTimer = new Timer();
- tempTimer.Interval = closeTimeSet * 1000;
- tempTimer.Tick += TempTimer_Tick;
- tempTimer.Enabled = true;
- }
- }
- private void TempTimer_Tick(object sender, EventArgs e)
- {
- try
- {
- this.Close();
- }
- catch { }
- }
- void SetButtonLocation(LYFZ.ComponentLibrary.ButtonExpand btn, int _y) {
- if (btn.Visible) {
- btn.Location = new Point(btn.Location.X, btn.Location.Y + _y);
- }
- }
- }
- }
|