BigIconForm.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. using Azylee.WinformSkin.APIUtils;
  2. using Azylee.WinformSkin.FormUI.NoTitle;
  3. using Azylee.WinformSkin.FormUI.Toast;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Windows.Forms;
  12. namespace Azylee.WinformSkin.FormUI.CustomTitle
  13. {
  14. public partial class BigIconForm : NoTitleForm
  15. {
  16. public BigIconForm()
  17. {
  18. InitializeComponent();
  19. }
  20. private void BigIconForm_Load(object sender, EventArgs e)
  21. {
  22. }
  23. #region 属性
  24. private int _BigIconFormHeadHeight = 68;
  25. [Category("Style")]
  26. [Description("标题栏高度")]
  27. [DefaultValue(typeof(int), "68")]
  28. public int BigIconFormHeadHeight
  29. {
  30. get { return _BigIconFormHeadHeight; }
  31. set
  32. {
  33. if (_BigIconFormHeadHeight != value)
  34. {
  35. _BigIconFormHeadHeight = value;
  36. BigIconFormPNHead.Height = value;
  37. }
  38. }
  39. }
  40. private bool _DoubleClickMax = true;
  41. [Category("Style")]
  42. [Description("双击最大化窗口")]
  43. [DefaultValue(typeof(bool), "true")]
  44. public bool DoubleClickMax
  45. {
  46. get { return _DoubleClickMax; }
  47. set
  48. {
  49. if (_DoubleClickMax != value)
  50. {
  51. _DoubleClickMax = value;
  52. }
  53. }
  54. }
  55. #endregion
  56. #region UI界面调整方法
  57. public void UIMax()
  58. {
  59. Invoke(new Action(() =>
  60. {
  61. if (WindowState != FormWindowState.Maximized)
  62. {
  63. MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  64. WindowState = FormWindowState.Maximized;
  65. }
  66. }));
  67. }
  68. #endregion
  69. #region 窗口操作:拖动、边框、最小化、最大化、还原、双击标题栏最大化、拖动标题栏还原、关闭
  70. /// <summary>
  71. /// 拖动窗口移动
  72. /// </summary>
  73. /// <param name="sender"></param>
  74. /// <param name="e"></param>
  75. private void BigIconFormLBHeadTitle_MouseMove(object sender, MouseEventArgs e)
  76. {
  77. if (e.Button == MouseButtons.Left)
  78. {
  79. FormStyleAPI.ReleaseCapture();
  80. FormStyleAPI.SendMessage(Handle, FormStyleAPI.WM_NCLBUTTONDOWN, FormStyleAPI.HTCAPTION, 0);
  81. }
  82. }
  83. /// <summary>
  84. /// 大小改变,刷新边框
  85. /// </summary>
  86. /// <param name="sender"></param>
  87. /// <param name="e"></param>
  88. private void BigIconFormBigIconForm_SizeChanged(object sender, EventArgs e)
  89. {
  90. SetBorder();
  91. BigIconFormPNHead.Height = BigIconFormHeadHeight;
  92. TMRefresh.Enabled = true;
  93. if (WindowState == FormWindowState.Maximized || WindowState == FormWindowState.Normal)
  94. {
  95. if (Visible && Opacity > 0)
  96. {
  97. TMRefreshStart();
  98. //ToastForm.Display("test", $"窗口显示,且为正常大小状态,透明度{Opacity}", 'i', 5000);
  99. }
  100. }
  101. }
  102. /// <summary>
  103. /// 最小化
  104. /// </summary>
  105. /// <param name="sender"></param>
  106. /// <param name="e"></param>
  107. private void BigIconFormBTFormMinBox_Click(object sender, EventArgs e)
  108. {
  109. WindowState = FormWindowState.Minimized;
  110. }
  111. /// <summary>
  112. /// 最大化及还原
  113. /// </summary>
  114. /// <param name="sender"></param>
  115. /// <param name="e"></param>
  116. private void BigIconFormBTFormMaxBox_Click(object sender, EventArgs e)
  117. {
  118. if (WindowState != FormWindowState.Maximized)
  119. {
  120. MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  121. WindowState = FormWindowState.Maximized;
  122. }
  123. else
  124. WindowState = FormWindowState.Normal;
  125. }
  126. private void BigIconFormLBHeadTitle_DoubleClick(object sender, EventArgs e)
  127. {
  128. if (_DoubleClickMax)
  129. {
  130. if (WindowState != FormWindowState.Maximized)
  131. {
  132. MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  133. WindowState = FormWindowState.Maximized;
  134. }
  135. else
  136. WindowState = FormWindowState.Normal;
  137. }
  138. }
  139. /// <summary>
  140. /// 关闭
  141. /// </summary>
  142. /// <param name="sender"></param>
  143. /// <param name="e"></param>
  144. private void BigIconFormBTFormCloseBox_Click(object sender, EventArgs e)
  145. {
  146. Close();
  147. }
  148. #endregion
  149. #region 窗口显示优化
  150. /// <summary>
  151. /// 重绘窗口计时器,防止win10出现部分区域透明
  152. /// </summary>
  153. /// <param name="sender"></param>
  154. /// <param name="e"></param>
  155. private void TMRefreshStart()
  156. {
  157. TMRefresh.Interval = 200;
  158. TMRefresh.Enabled = true;
  159. }
  160. private void TMRefresh_Tick(object sender, EventArgs e)
  161. {
  162. int maxInterval = 200 + 6;
  163. if (TMRefresh.Interval > maxInterval)
  164. {
  165. TMRefresh.Enabled = false;
  166. }
  167. else
  168. {
  169. Refresh();
  170. TMRefresh.Interval = TMRefresh.Interval + 1;
  171. }
  172. }
  173. #endregion
  174. }
  175. }