FrmDialog.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // ***********************************************************************
  2. // Assembly : HZH_Controls
  3. // Created : 08-08-2019
  4. //
  5. // ***********************************************************************
  6. // <copyright file="FrmDialog.cs">
  7. // Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
  8. // </copyright>
  9. //
  10. // Blog: https://www.cnblogs.com/bfyx
  11. // GitHub:https://github.com/kwwwvagaa/NetWinformControl
  12. // gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
  13. //
  14. // If you use this code, please keep this note.
  15. // ***********************************************************************
  16. using System;
  17. using System.Collections.Generic;
  18. using System.ComponentModel;
  19. using System.Data;
  20. using System.Drawing;
  21. using System.Linq;
  22. using System.Text;
  23. using System.Windows.Forms;
  24. namespace HZH_Controls.Forms
  25. {
  26. /// <summary>
  27. /// Class FrmDialog.
  28. /// Implements the <see cref="HZH_Controls.Forms.FrmBase" />
  29. /// </summary>
  30. /// <seealso cref="HZH_Controls.Forms.FrmBase" />
  31. public partial class FrmDialog : FrmBase
  32. {
  33. /// <summary>
  34. /// The BLN enter close
  35. /// </summary>
  36. bool blnEnterClose = true;
  37. /// <summary>
  38. /// Initializes a new instance of the <see cref="FrmDialog" /> class.
  39. /// </summary>
  40. /// <param name="strMessage">The string message.</param>
  41. /// <param name="strTitle">The string title.</param>
  42. /// <param name="blnShowCancel">if set to <c>true</c> [BLN show cancel].</param>
  43. /// <param name="blnShowClose">if set to <c>true</c> [BLN show close].</param>
  44. /// <param name="blnisEnterClose">if set to <c>true</c> [blnis enter close].</param>
  45. private FrmDialog(
  46. string strMessage,
  47. string strTitle,
  48. bool blnShowCancel = false,
  49. bool blnShowClose = false,
  50. bool blnisEnterClose = true)
  51. {
  52. InitializeComponent();
  53. InitFormMove(this.lblTitle);
  54. if (!string.IsNullOrWhiteSpace(strTitle))
  55. lblTitle.Text = strTitle;
  56. lblMsg.Text = strMessage;
  57. if (blnShowCancel)
  58. {
  59. this.tableLayoutPanel1.ColumnStyles[1].Width = 1;
  60. this.tableLayoutPanel1.ColumnStyles[2].Width = 50;
  61. }
  62. else
  63. {
  64. this.tableLayoutPanel1.ColumnStyles[1].Width = 0;
  65. this.tableLayoutPanel1.ColumnStyles[2].Width = 0;
  66. }
  67. //btnCancel.Visible = blnShowCancel;
  68. //ucSplitLine_V1.Visible = blnShowCancel;
  69. btnClose.Visible = blnShowClose;
  70. blnEnterClose = blnisEnterClose;
  71. //if (blnShowCancel)
  72. //{
  73. // btnOK.BtnForeColor = Color.FromArgb(255, 85, 51);
  74. //}
  75. }
  76. #region 显示一个模式信息框
  77. /// <summary>
  78. /// 功能描述:显示一个模式信息框
  79. /// 作  者:HZH
  80. /// 创建日期:2019-03-04 15:49:48
  81. /// 任务编号:POS
  82. /// </summary>
  83. /// <param name="owner">owner</param>
  84. /// <param name="strMessage">strMessage</param>
  85. /// <param name="strTitle">strTitle</param>
  86. /// <param name="blnShowCancel">blnShowCancel</param>
  87. /// <param name="isShowMaskDialog">isShowMaskDialog</param>
  88. /// <param name="blnShowClose">blnShowClose</param>
  89. /// <param name="blnIsEnterClose">if set to <c>true</c> [BLN is enter close].</param>
  90. /// <param name="deviationSize">大小偏移,当默认大小过大或过小时,可以进行调整(增量)</param>
  91. /// <returns>返回值</returns>
  92. public static DialogResult ShowDialog(
  93. IWin32Window owner,
  94. string strMessage,
  95. string strTitle = "提示",
  96. bool blnShowCancel = false,
  97. bool isShowMaskDialog = true,
  98. bool blnShowClose = false,
  99. bool blnIsEnterClose = true,
  100. Size? deviationSize = null)
  101. {
  102. DialogResult result = DialogResult.Cancel;
  103. if (owner == null || (owner is Control && (owner as Control).IsDisposed))
  104. {
  105. var frm = new FrmDialog(strMessage, strTitle, blnShowCancel, blnShowClose, blnIsEnterClose)
  106. {
  107. StartPosition = FormStartPosition.CenterScreen,
  108. IsShowMaskDialog = isShowMaskDialog,
  109. TopMost = true
  110. };
  111. if (deviationSize != null)
  112. {
  113. frm.Width += deviationSize.Value.Width;
  114. frm.Height += deviationSize.Value.Height;
  115. }
  116. result = frm.ShowDialog();
  117. }
  118. else
  119. {
  120. if (owner is Control)
  121. {
  122. owner = (owner as Control).FindForm();
  123. }
  124. var frm = new FrmDialog(strMessage, strTitle, blnShowCancel, blnShowClose, blnIsEnterClose)
  125. {
  126. StartPosition = (owner != null) ? FormStartPosition.CenterParent : FormStartPosition.CenterScreen,
  127. IsShowMaskDialog = isShowMaskDialog,
  128. TopMost = true
  129. };
  130. if (deviationSize != null)
  131. {
  132. frm.Width += deviationSize.Value.Width;
  133. frm.Height += deviationSize.Value.Height;
  134. }
  135. result = frm.ShowDialog(owner);
  136. }
  137. return result;
  138. }
  139. #endregion
  140. /// <summary>
  141. /// Handles the BtnClick event of the btnOK control.
  142. /// </summary>
  143. /// <param name="sender">The source of the event.</param>
  144. /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
  145. private void btnOK_BtnClick(object sender, EventArgs e)
  146. {
  147. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  148. }
  149. /// <summary>
  150. /// Handles the BtnClick event of the btnCancel control.
  151. /// </summary>
  152. /// <param name="sender">The source of the event.</param>
  153. /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
  154. private void btnCancel_BtnClick(object sender, EventArgs e)
  155. {
  156. this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  157. }
  158. /// <summary>
  159. /// Handles the MouseDown event of the btnClose control.
  160. /// </summary>
  161. /// <param name="sender">The source of the event.</param>
  162. /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
  163. private void btnClose_MouseDown(object sender, MouseEventArgs e)
  164. {
  165. this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  166. }
  167. /// <summary>
  168. /// Does the enter.
  169. /// </summary>
  170. protected override void DoEnter()
  171. {
  172. if (blnEnterClose)
  173. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  174. }
  175. /// <summary>
  176. /// Handles the VisibleChanged event of the FrmDialog control.
  177. /// </summary>
  178. /// <param name="sender">The source of the event.</param>
  179. /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
  180. private void FrmDialog_VisibleChanged(object sender, EventArgs e)
  181. {
  182. }
  183. }
  184. }