UIForm.1.Layout.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. namespace Microsoft.Windows.Forms
  5. {
  6. partial class UIForm
  7. {
  8. /// <summary>
  9. /// 获取或设置父控件
  10. /// </summary>
  11. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  12. public IUIControl UIParent
  13. {
  14. get
  15. {
  16. return null;
  17. }
  18. set
  19. {
  20. throw new NotSupportedException("不允许为 UIWindow 设置 Parent");
  21. }
  22. }
  23. private UIControl.UIControlCollection m_UIControls;
  24. /// <summary>
  25. /// 获取子控件集合
  26. /// </summary>
  27. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  28. public UIControl.UIControlCollection UIControls
  29. {
  30. get
  31. {
  32. this.CheckDisposed();
  33. if (this.m_UIControls == null)
  34. this.m_UIControls = new UIControl.UIControlCollection(this);
  35. return this.m_UIControls;
  36. }
  37. }
  38. private int m_LayoutSuspendCount;
  39. /// <summary>
  40. /// 获取布局操作是否被挂起
  41. /// </summary>
  42. public bool LayoutSuspended
  43. {
  44. get
  45. {
  46. return this.m_LayoutSuspendCount != 0;
  47. }
  48. }
  49. /// <summary>
  50. /// 挂起布局操作
  51. /// </summary>
  52. public new void SuspendLayout()
  53. {
  54. this.m_LayoutSuspendCount++;
  55. base.SuspendLayout();
  56. }
  57. /// <summary>
  58. /// 恢复挂起的布局操作
  59. /// </summary>
  60. public new void ResumeLayout()
  61. {
  62. this.ResumeLayout(false);
  63. }
  64. /// <summary>
  65. /// 恢复挂起的布局操作,可选择是否强制执行布局
  66. /// </summary>
  67. /// <param name="performLayout">如果强制则为 true, 否则为 false</param>
  68. public new void ResumeLayout(bool performLayout)
  69. {
  70. this.m_LayoutSuspendCount--;
  71. this.DoLayoutCore(performLayout);
  72. base.ResumeLayout(performLayout);
  73. }
  74. /// <summary>
  75. /// 如果未挂起布局操作则重新计算子控件布局
  76. /// </summary>
  77. public void DoLayout()
  78. {
  79. this.DoLayoutCore(false);
  80. }
  81. /// <summary>
  82. /// 重新计算子控件布局,可选择是否强制执行布局
  83. /// </summary>
  84. /// <param name="performLayout">如果强制则为 true, 否则为 false</param>
  85. protected void DoLayoutCore(bool performLayout)
  86. {
  87. if (performLayout || !this.LayoutSuspended)
  88. UIControl.DoLayoutInternal(this);
  89. }
  90. /// <summary>
  91. /// 将所在 Win32 控件坐标系的点转换为控件坐标系的点
  92. /// </summary>
  93. /// <param name="p">点</param>
  94. /// <returns>转换后的点</returns>
  95. public Point PointToUIControl(Point p)
  96. {
  97. return p;
  98. }
  99. /// <summary>
  100. /// 将控件坐标系的点转换为所在 Win32 控件坐标系的点
  101. /// </summary>
  102. /// <param name="p">点</param>
  103. /// <returns>转换后的点</returns>
  104. public Point PointToUIWindow(Point p)
  105. {
  106. return p;
  107. }
  108. /// <summary>
  109. /// 将所在 Win32 控件坐标系的矩形转换为控件坐标系的矩形
  110. /// </summary>
  111. /// <param name="r">矩形</param>
  112. /// <returns>转换后的矩形</returns>
  113. public Rectangle RectangleToUIControl(Rectangle r)
  114. {
  115. return r;
  116. }
  117. /// <summary>
  118. /// 将控件坐标系的矩形转换为所在 Win32 控件坐标系的矩形
  119. /// </summary>
  120. /// <param name="r">矩形</param>
  121. /// <returns>转换后的矩形</returns>
  122. public Rectangle RectangleToUIWindow(Rectangle r)
  123. {
  124. return r;
  125. }
  126. /// <summary>
  127. /// 查找所在的 Win32 控件
  128. /// </summary>
  129. /// <returns>所在的 Win32 控件</returns>
  130. public IUIWindow FindUIWindow()
  131. {
  132. return this;
  133. }
  134. /// <summary>
  135. /// 根据坐标查找子控件
  136. /// </summary>
  137. /// <param name="p">坐标</param>
  138. /// <returns>子控件</returns>
  139. public UIControl FindUIChild(Point p)
  140. {
  141. return UIControl.FindUIChildInternal(this, p);
  142. }
  143. /// <summary>
  144. /// 根据名称查找子控件
  145. /// </summary>
  146. /// <param name="name">名称</param>
  147. /// <returns>子控件</returns>
  148. public UIControl FindUIChild(string name)
  149. {
  150. return UIControl.FindUIChildInternal(this, name);
  151. }
  152. /// <summary>
  153. /// 大小改变,重新计算布局
  154. /// </summary>
  155. /// <param name="e">计算布局</param>
  156. protected override void OnSizeChanged(EventArgs e)
  157. {
  158. base.OnSizeChanged(e);
  159. this.DoLayout();
  160. }
  161. }
  162. }