frmMessageBox.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace LYFZ.ComponentLibrary
  10. {
  11. public partial class frmMessageBox : LYFZ.ComponentLibrary.BaseFormSimple
  12. {
  13. Timer tempTimer;
  14. public bool bTimerUp = false;
  15. public int closeTimeSet = 1;
  16. public frmMessageBox()
  17. {
  18. InitializeComponent();
  19. this.btnExpandYes.Focus();
  20. this.btnAppFormExit.Click+=btnAppFormExit_Click2;
  21. }
  22. protected void btnAppFormExit_Click2(object sender, EventArgs e)
  23. {
  24. if (this.MsgBoxButtons == MessageBoxButtons.AbortRetryIgnore)
  25. { this.DialogResult = DialogResult.Ignore; }
  26. else if (this.MsgBoxButtons == MessageBoxButtons.OK)
  27. { this.DialogResult = DialogResult.OK; }
  28. else if (this.MsgBoxButtons == MessageBoxButtons.OKCancel)
  29. { this.DialogResult = DialogResult.Cancel; }
  30. else if (this.MsgBoxButtons == MessageBoxButtons.RetryCancel)
  31. { this.DialogResult = DialogResult.Cancel; }
  32. else if (this.MsgBoxButtons == MessageBoxButtons.YesNo)
  33. { this.DialogResult = DialogResult.No; }
  34. else if (this.MsgBoxButtons == MessageBoxButtons.YesNoCancel)
  35. { this.DialogResult = DialogResult.Cancel; }
  36. }
  37. MessageBoxButtons _MsgBoxButtons = MessageBoxButtons.OK;
  38. /// <summary>
  39. ///
  40. /// </summary>
  41. public MessageBoxButtons MsgBoxButtons
  42. {
  43. get { return _MsgBoxButtons; }
  44. set { _MsgBoxButtons = value; }
  45. }
  46. private void btnExpandOK_Click(object sender, EventArgs e)
  47. {
  48. if (this.btnExpandOK.Text == "否")
  49. {
  50. this.DialogResult = DialogResult.No;
  51. }
  52. else
  53. {
  54. this.DialogResult = DialogResult.OK;
  55. }
  56. this.Close();
  57. }
  58. private void btnExpandNo_Click(object sender, EventArgs e)
  59. {
  60. if (this.btnExpandNo.Text == "取消")
  61. {
  62. this.DialogResult = DialogResult.Cancel;
  63. }
  64. else
  65. {
  66. this.DialogResult = DialogResult.No;
  67. }
  68. this.Close();
  69. }
  70. private void btnExpandYes_Click(object sender, EventArgs e)
  71. {
  72. if (this.MsgBoxButtons == MessageBoxButtons.OKCancel)
  73. {
  74. this.DialogResult = DialogResult.OK;
  75. }
  76. else
  77. {
  78. this.DialogResult = DialogResult.Yes;
  79. }
  80. this.Close();
  81. }
  82. private void frmMessageBox_FormClosed(object sender, FormClosedEventArgs e)
  83. {
  84. }
  85. private void frmMessageBox_Load(object sender, EventArgs e)
  86. {
  87. switch (MsgBoxButtons)
  88. {
  89. case MessageBoxButtons.OK:
  90. this.btnExpandOK.Visible = true;
  91. this.btnExpandNo.Visible = false;
  92. this.btnExpandYes.Visible = false;
  93. break;
  94. case MessageBoxButtons.YesNo:
  95. this.btnExpandNo.Visible = true;
  96. this.btnExpandYes.Visible = true;
  97. this.btnExpandOK.Visible = false;
  98. break;
  99. case MessageBoxButtons.OKCancel:
  100. this.btnExpandNo.Visible = true;
  101. this.btnExpandYes.Visible = true;
  102. this.btnExpandOK.Visible = false;
  103. this.btnExpandYes.Text = "确定";
  104. this.btnExpandNo.Text = "取消";
  105. break;
  106. case MessageBoxButtons.YesNoCancel:
  107. this.btnExpandNo.Visible = true;
  108. this.btnExpandYes.Visible = true;
  109. this.btnExpandOK.Visible = true;
  110. this.btnExpandOK.Text = "否";
  111. this.btnExpandNo.Text = "取消";
  112. break;
  113. }
  114. SizeF size = this.CreateGraphics().MeasureString(this.lbMseValue.Text, this.lbMseValue.Font);
  115. if (Convert.ToInt32(size.Width) > this.Width - 10)
  116. {
  117. this.lbMseValue.TextAlign = ContentAlignment.MiddleLeft;
  118. }
  119. if (size.Width / this.Width > 3)
  120. {
  121. int tempHeight = (Convert.ToInt32(size.Width / this.Width) - 3) * 20;
  122. this.Height = this.Height + tempHeight;
  123. this.plContent.Height = this.plContent.Height + tempHeight;
  124. //this.btnExpandOK.Location = new Point(this.btnExpandOK.Location.X, this.btnExpandOK.Location.Y + tempHeight);
  125. SetButtonLocation(this.btnExpandOK,tempHeight);
  126. SetButtonLocation(this.btnExpandNo, tempHeight);
  127. SetButtonLocation(this.btnExpandYes, tempHeight);
  128. }
  129. if(bTimerUp)
  130. {
  131. tempTimer = new Timer();
  132. tempTimer.Interval = closeTimeSet * 1000;
  133. tempTimer.Tick += TempTimer_Tick;
  134. tempTimer.Enabled = true;
  135. }
  136. }
  137. private void TempTimer_Tick(object sender, EventArgs e)
  138. {
  139. try
  140. {
  141. this.Close();
  142. }
  143. catch { }
  144. }
  145. void SetButtonLocation(LYFZ.ComponentLibrary.ButtonExpand btn, int _y) {
  146. if (btn.Visible) {
  147. btn.Location = new Point(btn.Location.X, btn.Location.Y + _y);
  148. }
  149. }
  150. }
  151. }