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.

159 lines
4.9 KiB

  1. #if NETFX || NETCORE
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace Apewer.Surface
  9. {
  10. /// <summary>基本窗体。</summary>
  11. public class BaseForm : Form
  12. {
  13. #region this & base
  14. private IContainer _components = null;
  15. private void InitializeComponent()
  16. {
  17. this.SuspendLayout();
  18. this.AutoScaleMode = AutoScaleMode.None;
  19. this.BackColor = FormsUtility.White;
  20. this.Font = FormsUtility.DefaultFont;
  21. this.ClientSize = new Size(600, 400);
  22. this.FormBorderStyle = FormBorderStyle.None;
  23. this.StartPosition = FormStartPosition.CenterScreen;
  24. this.KeyPreview = true;
  25. this.ResumeLayout(false);
  26. }
  27. /// <summary>构造函数。</summary>
  28. public BaseForm()
  29. {
  30. InitializeComponent();
  31. }
  32. #endregion
  33. #region override
  34. private bool _resizeable = true;
  35. /// <summary>是否能够调整窗体大小。</summary>
  36. public bool Resizeable
  37. {
  38. get { return _resizeable; }
  39. set { _resizeable = value; }
  40. }
  41. /// <summary>释放资源。</summary>
  42. /// <param name="disposing">释放非托对象。</param>
  43. protected override void Dispose(bool disposing)
  44. {
  45. if (disposing && (_components != null)) _components.Dispose();
  46. base.Dispose(disposing);
  47. }
  48. ///// <summary>允许点击任务栏最小化。</summary>
  49. //protected override CreateParams CreateParams
  50. //{
  51. // get
  52. // {
  53. // const int WS_MINIMIZEBOX = 0x00020000; // winuser.h
  54. // CreateParams cp = base.CreateParams;
  55. // cp.Style = cp.Style | WS_MINIMIZEBOX; // 允许最小化操作
  56. // return cp;
  57. // }
  58. //}
  59. /// <summary>允许调节窗口大小。</summary>
  60. protected override void WndProc(ref Message m)
  61. {
  62. const int htleft = 10;
  63. const int htright = 11;
  64. const int httop = 12;
  65. const int httopleft = 13;
  66. const int httopright = 14;
  67. const int htbottom = 15;
  68. const int htbottomleft = 0x10;
  69. const int htbottomright = 17;
  70. switch (m.Msg)
  71. {
  72. case 0x0084:
  73. base.WndProc(ref m);
  74. if (Resizeable)
  75. {
  76. Point vPoint = new Point((int)m.LParam & 0xFFFF,
  77. (int)m.LParam >> 16 & 0xFFFF);
  78. vPoint = PointToClient(vPoint);
  79. if (vPoint.X <= 5)
  80. if (vPoint.Y <= 5)
  81. m.Result = (IntPtr)httopleft;
  82. else if (vPoint.Y >= ClientSize.Height - 5)
  83. m.Result = (IntPtr)htbottomleft;
  84. else m.Result = (IntPtr)htleft;
  85. else if (vPoint.X >= ClientSize.Width - 5)
  86. if (vPoint.Y <= 5)
  87. m.Result = (IntPtr)httopright;
  88. else if (vPoint.Y >= ClientSize.Height - 5)
  89. m.Result = (IntPtr)htbottomright;
  90. else m.Result = (IntPtr)htright;
  91. else if (vPoint.Y <= 5)
  92. m.Result = (IntPtr)httop;
  93. else if (vPoint.Y >= ClientSize.Height - 5)
  94. m.Result = (IntPtr)htbottom;
  95. }
  96. break;
  97. case 0x0201: // 左键
  98. m.Msg = 0x00A1; // 更改消息为非客户区按下鼠标
  99. m.LParam = IntPtr.Zero; // 默认值
  100. m.WParam = new IntPtr(2); // 鼠标放在标题栏内
  101. base.WndProc(ref m);
  102. break;
  103. default:
  104. base.WndProc(ref m);
  105. break;
  106. }
  107. }
  108. #endregion
  109. #region public accessor
  110. #endregion
  111. #region protected derivation
  112. /// <summary>界面线程调用器。</summary>
  113. protected delegate void Invoker();
  114. /// <summary>优化性能:开启双缓冲。</summary>
  115. protected void Optimize()
  116. {
  117. // SetStyle(ControlStyles.ResizeRedraw, value);
  118. // SetStyle(ControlStyles.Selectable, true);
  119. SetStyle(ControlStyles.UserPaint, true);
  120. SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  121. SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  122. SetStyle(ControlStyles.DoubleBuffer, true);
  123. // SetStyle(ControlStyles.Opaque, true);
  124. UpdateStyles();
  125. }
  126. #endregion
  127. }
  128. }
  129. #endif