革博士V2程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
7.4 KiB

  1. using MaiMuControl.Device;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Runtime.InteropServices;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace GeBoShi.UIKits.MaiMuMenu
  13. {
  14. public partial class UITitel_LT : UserControl
  15. {
  16. public MenuStrip UserMenuStrip = null;
  17. private Form _fartherForm = null;
  18. public Form FatherForm
  19. {
  20. get { return _fartherForm; }
  21. set
  22. {
  23. if ( value != null)
  24. {
  25. _original_Height = value.Height;
  26. _original_Width = value.Width;
  27. _original_Top = value.Top;
  28. _original_Left = value.Left;
  29. }
  30. _fartherForm = value;
  31. }
  32. }
  33. private int _original_Height;
  34. private int _original_Width;
  35. private int _original_Top;
  36. private int _original_Left;
  37. private int _windowsState;
  38. public UITitel_LT()
  39. {
  40. InitializeComponent();
  41. this.Dock = DockStyle.Top;
  42. if(UserMenuStrip == null)
  43. this.UimenuStrip.Visible = false;
  44. else
  45. this.UimenuStrip = UserMenuStrip;
  46. }
  47. public void ShowMenu()
  48. {
  49. if (UserMenuStrip == null)
  50. this.UimenuStrip.Visible = false;
  51. else
  52. {
  53. UserMenuStrip.AutoSize = false;
  54. UserMenuStrip.Height = this.Height;
  55. this.tableLayoutPanel1.Controls.Remove( this.UimenuStrip);
  56. //this.UimenuStrip = UserMenuStrip;
  57. //this.UimenuStrip.Visible = true;
  58. this.tableLayoutPanel1.Controls.Add(UserMenuStrip, 1, 0);
  59. UserMenuStrip.Renderer = new MaiMuMenuRender();
  60. }
  61. }
  62. public void ShowContrlBox(bool min, bool max, bool close, bool size = false)
  63. {
  64. this.tsbMin.Visible = min;
  65. this.tsbMax.Visible = max;
  66. this.tsbClose.Visible = close;
  67. this.tsbSize.Visible = size;
  68. }
  69. private void tsbSize_Click(object sender, EventArgs e)
  70. {
  71. }
  72. private void tsbMin_Click(object sender, EventArgs e)
  73. {
  74. FatherForm.WindowState = FormWindowState.Minimized;
  75. _windowsState = (int)FormWindowState.Minimized;
  76. }
  77. private void tsbMax_Click(object sender, EventArgs e)
  78. {
  79. //if (FatherForm.WindowState != FormWindowState.Maximized)
  80. if((FatherForm.Width < SystemInformation.WorkingArea.Width)&&(FatherForm.Height < SystemInformation.WorkingArea.Height))
  81. {
  82. _windowsState = (int)FormWindowState.Maximized;
  83. //FatherForm.WindowState = FormWindowState.Maximized;
  84. FatherForm.Top = 0;
  85. FatherForm.Left = 0;
  86. FatherForm.Width = SystemInformation.WorkingArea.Width;
  87. FatherForm.Height = SystemInformation.WorkingArea.Height;
  88. }
  89. else
  90. {
  91. _windowsState = (int)FormWindowState.Normal;
  92. //FatherForm.WindowState = FormWindowState.Normal;
  93. FatherForm.Top = (SystemInformation.WorkingArea.Height - _original_Height) / 2;
  94. FatherForm.Left = (SystemInformation.WorkingArea.Width - _original_Width) / 2;
  95. FatherForm.Width = _original_Width;
  96. FatherForm.Height = _original_Height;
  97. //FatherForm.StartPosition = FormStartPosition.CenterScreen;
  98. }
  99. }
  100. private void tsbClose_Click(object sender, EventArgs e)
  101. {
  102. FatherForm.Close();
  103. }
  104. #region 鼠标按住拖动界面
  105. [DllImport("user32.dll")]
  106. public static extern bool ReleaseCapture();
  107. [DllImport("user32.dll")]
  108. public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  109. public const int WM_SYSCOMMAND = 0x0112;
  110. public const int SC_MOVE = 0xF010;
  111. public const int HTCAPTION = 0x0002;
  112. private void UITitel_MouseDown(object sender, MouseEventArgs e)
  113. {
  114. ReleaseCapture();
  115. SendMessage(FatherForm.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  116. }
  117. private void tableLayoutPanel1_MouseDown(object sender, MouseEventArgs e)
  118. {
  119. ReleaseCapture();
  120. SendMessage(FatherForm.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  121. }
  122. private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
  123. {
  124. ReleaseCapture();
  125. SendMessage(FatherForm.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  126. }
  127. #endregion
  128. private void skinToolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  129. {
  130. }
  131. #region 界面放大缩小
  132. bool isMouseDown = false; //表示鼠标当前是否处于按下状态,初始值为否
  133. Point size_change = Point.Empty;
  134. private void tsbSize_MouseDown(object sender, MouseEventArgs e)
  135. {
  136. isMouseDown = true;
  137. FatherForm.Cursor = Cursors.SizeNESW;
  138. this.Cursor = Cursors.SizeNESW;
  139. size_change = e.Location;
  140. }
  141. private void tsbSize_MouseMove(object sender, MouseEventArgs e)
  142. {
  143. ResizeWindow(e);
  144. }
  145. private void tsbSize_MouseUp(object sender, MouseEventArgs e)
  146. {
  147. isMouseDown = false;
  148. FatherForm.Cursor = Cursors.Default;
  149. this.Cursor = Cursors.Default;
  150. }
  151. private void ResizeWindow(MouseEventArgs e)
  152. {
  153. //这个判断很重要,只有在鼠标按下时才能拖拽改变窗体大小,如果不作判断,那么鼠标弹起和按下时,窗体都可以改变
  154. if (!isMouseDown)
  155. return;
  156. //MousePosition的参考点是屏幕的左上角,表示鼠标当前相对于屏幕左上角的坐标this.left和this.top的参考点也是屏幕,属性MousePosition是该程序的重点
  157. if (FatherForm.Cursor == Cursors.SizeNESW)
  158. {
  159. //此行代码在mousemove事件中已经写过,在此再写一遍,并不多余,一定要写
  160. this.Cursor = Cursors.SizeNESW;
  161. //下面是改变窗体宽和高的代码,不明白的可以仔细思考一下
  162. FatherForm.Width = FatherForm.Width + (e.Location.X - size_change.X);
  163. FatherForm.Top = FatherForm.Top + (e.Location.Y - size_change.Y);
  164. FatherForm.Height = FatherForm.Height - (e.Location.Y - size_change.Y) ;
  165. this.Refresh();
  166. }
  167. //即使鼠标按下,但是不在窗口右和下边缘,那么也不能改变窗口大小
  168. else
  169. this.Cursor = Cursors.Arrow;
  170. }
  171. private void tsbSize_MouseLeave(object sender, EventArgs e)
  172. {
  173. isMouseDown = false;
  174. FatherForm.Cursor = Cursors.Default;
  175. this.Cursor = Cursors.Default;
  176. }
  177. #endregion
  178. }
  179. }