frmMessageBox.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. public frmMessageBox()
  14. {
  15. InitializeComponent();
  16. this.btnExpandYes.Focus();
  17. this.btnAppFormExit.Click+=btnAppFormExit_Click2;
  18. }
  19. protected void btnAppFormExit_Click2(object sender, EventArgs e)
  20. {
  21. if (this.MsgBoxButtons == MessageBoxButtons.AbortRetryIgnore)
  22. { this.DialogResult = DialogResult.Ignore; }
  23. else if (this.MsgBoxButtons == MessageBoxButtons.OK)
  24. { this.DialogResult = DialogResult.OK; }
  25. else if (this.MsgBoxButtons == MessageBoxButtons.OKCancel)
  26. { this.DialogResult = DialogResult.Cancel; }
  27. else if (this.MsgBoxButtons == MessageBoxButtons.RetryCancel)
  28. { this.DialogResult = DialogResult.Cancel; }
  29. else if (this.MsgBoxButtons == MessageBoxButtons.YesNo)
  30. { this.DialogResult = DialogResult.No; }
  31. else if (this.MsgBoxButtons == MessageBoxButtons.YesNoCancel)
  32. { this.DialogResult = DialogResult.Cancel; }
  33. }
  34. MessageBoxButtons _MsgBoxButtons = MessageBoxButtons.OK;
  35. /// <summary>
  36. ///
  37. /// </summary>
  38. public MessageBoxButtons MsgBoxButtons
  39. {
  40. get { return _MsgBoxButtons; }
  41. set { _MsgBoxButtons = value; }
  42. }
  43. private void btnExpandOK_Click(object sender, EventArgs e)
  44. {
  45. if (this.btnExpandOK.Text == "否")
  46. {
  47. this.DialogResult = DialogResult.No;
  48. }
  49. else
  50. {
  51. this.DialogResult = DialogResult.OK;
  52. }
  53. this.Close();
  54. }
  55. private void btnExpandNo_Click(object sender, EventArgs e)
  56. {
  57. if (this.btnExpandNo.Text == "取消")
  58. {
  59. this.DialogResult = DialogResult.Cancel;
  60. }
  61. else
  62. {
  63. this.DialogResult = DialogResult.No;
  64. }
  65. this.Close();
  66. }
  67. private void btnExpandYes_Click(object sender, EventArgs e)
  68. {
  69. this.DialogResult = DialogResult.Yes;
  70. this.Close();
  71. }
  72. private void frmMessageBox_FormClosed(object sender, FormClosedEventArgs e)
  73. {
  74. }
  75. private void frmMessageBox_Load(object sender, EventArgs e)
  76. {
  77. switch (MsgBoxButtons)
  78. {
  79. case MessageBoxButtons.OK:
  80. this.btnExpandOK.Visible = true;
  81. this.btnExpandNo.Visible = false;
  82. this.btnExpandYes.Visible = false;
  83. break;
  84. case MessageBoxButtons.YesNo:
  85. this.btnExpandNo.Visible = true;
  86. this.btnExpandYes.Visible = true;
  87. this.btnExpandOK.Visible = false;
  88. break;
  89. case MessageBoxButtons.YesNoCancel:
  90. this.btnExpandNo.Visible = true;
  91. this.btnExpandYes.Visible = true;
  92. this.btnExpandOK.Visible = true;
  93. this.btnExpandOK.Text = "否";
  94. this.btnExpandNo.Text = "取消";
  95. break;
  96. }
  97. SizeF size = this.CreateGraphics().MeasureString(this.lbMseValue.Text, this.lbMseValue.Font);
  98. if (Convert.ToInt32(size.Width) > this.Width - 10)
  99. {
  100. this.lbMseValue.TextAlign = ContentAlignment.MiddleLeft;
  101. }
  102. if (size.Width / this.Width > 3)
  103. {
  104. int tempHeight = (Convert.ToInt32(size.Width / this.Width) - 3) * 20;
  105. this.Height = this.Height + tempHeight;
  106. this.plContent.Height = this.plContent.Height + tempHeight;
  107. //this.btnExpandOK.Location = new Point(this.btnExpandOK.Location.X, this.btnExpandOK.Location.Y + tempHeight);
  108. SetButtonLocation(this.btnExpandOK,tempHeight);
  109. SetButtonLocation(this.btnExpandNo, tempHeight);
  110. SetButtonLocation(this.btnExpandYes, tempHeight);
  111. }
  112. }
  113. void SetButtonLocation(LYFZ.ComponentLibrary.ButtonExpand btn, int _y) {
  114. if (btn.Visible) {
  115. btn.Location = new Point(btn.Location.X, btn.Location.Y + _y);
  116. }
  117. }
  118. }
  119. }