UILabel.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Drawing;
  2. using System.Drawing.Text;
  3. using System.Windows.Forms;
  4. using Microsoft.Drawing;
  5. namespace Microsoft.Windows.Forms
  6. {
  7. /// <summary>
  8. /// 虚拟标签控件
  9. /// </summary>
  10. public class UILabel : UIControl
  11. {
  12. private TextRenderingHint m_TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  13. /// <summary>
  14. /// 文本呈现质量
  15. /// </summary>
  16. public virtual TextRenderingHint TextRenderingHint
  17. {
  18. get
  19. {
  20. return this.m_TextRenderingHint;
  21. }
  22. set
  23. {
  24. if (value != this.m_TextRenderingHint)
  25. {
  26. this.m_TextRenderingHint = value;
  27. this.Invalidate();
  28. }
  29. }
  30. }
  31. private ContentAlignment m_TextAlign = ContentAlignment.MiddleCenter;
  32. /// <summary>
  33. /// 文本对齐方式
  34. /// </summary>
  35. public virtual ContentAlignment TextAlign
  36. {
  37. get
  38. {
  39. return this.m_TextAlign;
  40. }
  41. set
  42. {
  43. if (value != this.m_TextAlign)
  44. {
  45. this.m_TextAlign = value;
  46. this.Invalidate();
  47. }
  48. }
  49. }
  50. /// <summary>
  51. /// 渲染控件
  52. /// </summary>
  53. /// <param name="e">数据</param>
  54. protected override void RenderSelf(PaintEventArgs e)
  55. {
  56. //准备
  57. Graphics g = e.Graphics;
  58. Rectangle rect = RectangleEx.Subtract(this.ClientRectangle, this.Padding);
  59. //渲染
  60. this.Sprite.BackColor = this.BackColor;
  61. this.Sprite.Font = this.Font;
  62. this.Sprite.Text = this.Text;
  63. this.Sprite.TextRenderingHint = this.TextRenderingHint;
  64. this.Sprite.TextAlign = this.TextAlign;
  65. this.Sprite.BorderVisibleStyle = BorderVisibleStyle.None;
  66. this.Sprite.State = this.State;
  67. this.Sprite.BeginRender(g);
  68. this.Sprite.RenderText(rect);
  69. this.Sprite.EndRender();
  70. }
  71. }
  72. }