LayoutData.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. using System.Drawing;
  2. using System.Windows.Forms;
  3. using Microsoft.Drawing;
  4. namespace Microsoft.Windows.Forms.Layout
  5. {
  6. /// <summary>
  7. /// 布局数据
  8. /// </summary>
  9. public sealed class LayoutData : DisposableMini
  10. {
  11. /// <summary>
  12. /// 测试用绘图对象
  13. /// </summary>
  14. public Graphics Graphics;
  15. /// <summary>
  16. /// 区域
  17. /// </summary>
  18. public Rectangle ClientRectangle;
  19. /// <summary>
  20. /// 边距
  21. /// </summary>
  22. public Padding Padding;
  23. /// <summary>
  24. /// 文本图片相对位置
  25. /// </summary>
  26. public TextImageRelation TextImageRelation;
  27. /// <summary>
  28. /// 左右反转样式
  29. /// </summary>
  30. public RightToLeft RightToLeft;
  31. /// <summary>
  32. /// 图片大小
  33. /// </summary>
  34. public Size ImageSize;
  35. /// <summary>
  36. /// 图片对齐方式
  37. /// </summary>
  38. public ContentAlignment ImageAlign;
  39. /// <summary>
  40. /// 图片偏移量
  41. /// </summary>
  42. public Point ImageOffset;
  43. /// <summary>
  44. /// 文本
  45. /// </summary>
  46. public string Text;
  47. /// <summary>
  48. /// 字体
  49. /// </summary>
  50. public Font Font;
  51. /// <summary>
  52. /// 文本对齐方式
  53. /// </summary>
  54. public ContentAlignment TextAlign;
  55. /// <summary>
  56. /// 文本偏移量
  57. /// </summary>
  58. public Point TextOffset;
  59. /// <summary>
  60. /// 输出-图片区域(必须先调用Layout()方法)
  61. /// </summary>
  62. public Rectangle OutImageBounds;//[OUT]
  63. /// <summary>
  64. /// 输出-文本区域(必须先调用Layout()方法)
  65. /// </summary>
  66. public Rectangle OutTextBounds;//[OUT]
  67. //==================
  68. private bool m_IsLayouted;
  69. /// <summary>
  70. /// 是否执行过布局操作
  71. /// </summary>
  72. public bool IsLayouted
  73. {
  74. get
  75. {
  76. return this.m_IsLayouted;
  77. }
  78. }
  79. private Rectangle? m_CurrentClientRectangle;
  80. /// <summary>
  81. /// 当前区域,已减去边距
  82. /// </summary>
  83. public Rectangle CurrentClientRectangle
  84. {
  85. get
  86. {
  87. if (this.m_CurrentClientRectangle == null)
  88. this.m_CurrentClientRectangle = RectangleEx.Subtract(this.ClientRectangle, this.Padding);
  89. return this.m_CurrentClientRectangle.Value;
  90. }
  91. }
  92. private TextImageRelation? m_CurrentTextImageRelation;
  93. /// <summary>
  94. /// 当前文本图片相对位置,已通过左右反转样式翻译
  95. /// </summary>
  96. public TextImageRelation CurrentTextImageRelation
  97. {
  98. get
  99. {
  100. if (this.m_CurrentTextImageRelation == null)
  101. this.m_CurrentTextImageRelation = LayoutOptions.RtlTranslateRelation(this.TextImageRelation, this.RightToLeft);
  102. return this.m_CurrentTextImageRelation.Value;
  103. }
  104. }
  105. private StringFormat m_CurrentStringFormat;
  106. /// <summary>
  107. /// 当前文本格式,渲染文本时使用
  108. /// </summary>
  109. public StringFormat CurrentStringFormat
  110. {
  111. get
  112. {
  113. if (this.m_CurrentStringFormat == null)
  114. this.m_CurrentStringFormat = LayoutOptions.GetStringFormat(this.TextAlign, this.RightToLeft);
  115. return this.m_CurrentStringFormat;
  116. }
  117. }
  118. private ContentAlignment? m_CurrentImageAlign;
  119. /// <summary>
  120. /// 当前图片对齐方式,已通过左右反转样式翻译
  121. /// </summary>
  122. public ContentAlignment CurrentImageAlign
  123. {
  124. get
  125. {
  126. if (this.m_CurrentImageAlign == null)
  127. this.m_CurrentImageAlign = LayoutOptions.RtlTranslateAlignment(this.ImageAlign, this.RightToLeft);
  128. return this.m_CurrentImageAlign.Value;
  129. }
  130. }
  131. private ContentAlignment? m_CurrentTextAlign;
  132. /// <summary>
  133. /// 当前文本对齐方式,已通过左右反转样式翻译
  134. /// </summary>
  135. public ContentAlignment CurrentTextAlign
  136. {
  137. get
  138. {
  139. if (this.m_CurrentTextAlign == null)
  140. this.m_CurrentTextAlign = LayoutOptions.RtlTranslateAlignment(this.TextAlign, this.RightToLeft);
  141. return this.m_CurrentTextAlign.Value;
  142. }
  143. }
  144. /// <summary>
  145. /// 构造函数
  146. /// </summary>
  147. public LayoutData()
  148. {
  149. }
  150. /// <summary>
  151. /// 布局文本和图片.该方法可被调用多次,但再生命周期内布局操作只会被执行一次.
  152. /// </summary>
  153. public void DoLayout()
  154. {
  155. if (this.m_IsLayouted)
  156. return;
  157. this.m_IsLayouted = true;
  158. LayoutOptions.LayoutTextAndImage(this);
  159. }
  160. /// <summary>
  161. /// 释放资源
  162. /// </summary>
  163. /// <param name="disposing">释放托管资源为true,否则为false</param>
  164. protected override void Dispose(bool disposing)
  165. {
  166. if (this.m_CurrentStringFormat != null)
  167. {
  168. this.m_CurrentStringFormat.Dispose();
  169. this.m_CurrentStringFormat = null;
  170. }
  171. }
  172. }
  173. }