UIForm.4.Render.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System.ComponentModel;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using Microsoft.Drawing;
  5. using Microsoft.Win32;
  6. namespace Microsoft.Windows.Forms
  7. {
  8. partial class UIForm
  9. {
  10. private Sprite m_Sprite;
  11. /// <summary>
  12. /// 获取精灵
  13. /// </summary>
  14. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  15. protected virtual Sprite Sprite
  16. {
  17. get
  18. {
  19. this.CheckDisposed();
  20. if (this.m_Sprite == null)
  21. this.m_Sprite = new Sprite(this);
  22. return this.m_Sprite;
  23. }
  24. }
  25. private DoubleBufferedGraphics m_DoubleBufferedGraphics;
  26. /// <summary>
  27. /// 双缓冲接口
  28. /// </summary>
  29. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  30. DoubleBufferedGraphics IUIWindow.DoubleBufferedGraphics
  31. {
  32. get
  33. {
  34. this.CheckDisposed();
  35. if (this.m_DoubleBufferedGraphics == null)
  36. this.m_DoubleBufferedGraphics = new DoubleBufferedGraphics(this);
  37. return this.m_DoubleBufferedGraphics;
  38. }
  39. }
  40. private int m_UpdateSuspendCount;
  41. /// <summary>
  42. /// 获取布局操作是否被挂起
  43. /// </summary>
  44. public bool UpdateSuspended
  45. {
  46. get
  47. {
  48. return this.m_UpdateSuspendCount != 0;
  49. }
  50. }
  51. /// <summary>
  52. /// 渲染控件
  53. /// </summary>
  54. /// <param name="e">数据</param>
  55. protected virtual void RenderSelf(PaintEventArgs e)
  56. {
  57. //准备
  58. Graphics g = e.Graphics;
  59. Rectangle rect = this.ClientRectangle;
  60. //渲染
  61. this.Sprite.BackColor = this.BackColor;
  62. this.Sprite.BeginRender(g);
  63. this.Sprite.RenderBackColor(rect);
  64. this.Sprite.RenderBorder(rect);
  65. this.Sprite.EndRender();
  66. }
  67. /// <summary>
  68. /// 渲染子控件
  69. /// </summary>
  70. /// <param name="e">数据</param>
  71. protected virtual void RenderChildren(PaintEventArgs e)
  72. {
  73. foreach (IUIControl control in this.UIControls)
  74. {
  75. if (control.Visible)
  76. using (new TranslateGraphics(e.Graphics, control.Location))
  77. control.RenderCore(e);
  78. }
  79. }
  80. /// <summary>
  81. /// 渲染控件和子控件
  82. /// </summary>
  83. /// <param name="e">数据</param>
  84. void IUIControl.RenderCore(PaintEventArgs e)
  85. {
  86. this.RenderSelf(e);
  87. this.RenderChildren(e);
  88. this.RaisePaintEvent(this, e);
  89. }
  90. /// <summary>
  91. /// 挂起刷新 UI
  92. /// </summary>
  93. public void BeginUpdate()
  94. {
  95. if (this.m_UpdateSuspendCount == 0 && this.Visible)
  96. Util.BeginUpdate(this.Handle);
  97. this.m_UpdateSuspendCount++;
  98. }
  99. /// <summary>
  100. /// 恢复刷新 UI
  101. /// </summary>
  102. public void EndUpdate()
  103. {
  104. this.EndUpdate(false);
  105. }
  106. /// <summary>
  107. /// 恢复刷新 UI,可以选择强制刷新
  108. /// </summary>
  109. /// <param name="forceUpdate">若要执行刷新为 true,否则为 false</param>
  110. public void EndUpdate(bool forceUpdate)
  111. {
  112. this.m_UpdateSuspendCount--;
  113. if (!this.UpdateSuspended)
  114. {
  115. if (this.Visible)
  116. {
  117. Util.EndUpdate(this.Handle);
  118. this.Refresh();
  119. }
  120. }
  121. else if (forceUpdate)
  122. {
  123. if (this.Visible)
  124. {
  125. Util.EndUpdate(this.Handle);
  126. this.Refresh();
  127. Util.BeginUpdate(this.Handle);
  128. }
  129. }
  130. }
  131. /// <summary>
  132. /// 处理重绘事件
  133. /// </summary>
  134. /// <param name="e">数据</param>
  135. protected override void OnPaint(PaintEventArgs e)
  136. {
  137. PaintManager.OnPaint(this, e);
  138. }
  139. }
  140. }