UCListItemExt.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // ***********************************************************************
  2. // Assembly : HZH_Controls
  3. // Created : 08-08-2019
  4. //
  5. // ***********************************************************************
  6. // <copyright file="UCListItemExt.cs">
  7. // Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
  8. // </copyright>
  9. //
  10. // Blog: https://www.cnblogs.com/bfyx
  11. // GitHub:https://github.com/kwwwvagaa/NetWinformControl
  12. // gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
  13. //
  14. // If you use this code, please keep this note.
  15. // ***********************************************************************
  16. using System;
  17. using System.Collections.Generic;
  18. using System.ComponentModel;
  19. using System.Drawing;
  20. using System.Data;
  21. using System.Linq;
  22. using System.Text;
  23. using System.Windows.Forms;
  24. namespace HZH_Controls.Controls
  25. {
  26. /// <summary>
  27. /// Class UCListItemExt.
  28. /// Implements the <see cref="System.Windows.Forms.UserControl" />
  29. /// </summary>
  30. /// <seealso cref="System.Windows.Forms.UserControl" />
  31. [ToolboxItem(false)]
  32. public partial class UCListItemExt : UserControl
  33. {
  34. /// <summary>
  35. /// Gets or sets the title.
  36. /// </summary>
  37. /// <value>The title.</value>
  38. [Description("标题"), Category("自定义")]
  39. public string Title
  40. {
  41. get { return label1.Text; }
  42. set { label1.Text = value; }
  43. }
  44. /// <summary>
  45. /// Gets or sets the title2.
  46. /// </summary>
  47. /// <value>The title2.</value>
  48. [Description("副标题"), Category("自定义")]
  49. public string Title2
  50. {
  51. get { return label3.Text; }
  52. set
  53. {
  54. label3.Text = value;
  55. label3.Visible = !string.IsNullOrEmpty(value);
  56. var g = label3.CreateGraphics();
  57. var size = g.MeasureString(value, label3.Font);
  58. label3.Width = (int)size.Width + 10;
  59. }
  60. }
  61. /// <summary>
  62. /// Gets or sets the title font.
  63. /// </summary>
  64. /// <value>The title font.</value>
  65. [Description("标题字体"), Category("自定义")]
  66. public Font TitleFont
  67. {
  68. get { return label1.Font; }
  69. set
  70. {
  71. label1.Font = value;
  72. }
  73. }
  74. /// <summary>
  75. /// Gets or sets the title2 font.
  76. /// </summary>
  77. /// <value>The title2 font.</value>
  78. [Description("副标题字体"), Category("自定义")]
  79. public Font Title2Font
  80. {
  81. get { return label3.Font; }
  82. set
  83. {
  84. label3.Font = value;
  85. }
  86. }
  87. /// <summary>
  88. /// Gets or sets the color of the item back.
  89. /// </summary>
  90. /// <value>The color of the item back.</value>
  91. [Description("背景色"), Category("自定义")]
  92. public Color ItemBackColor
  93. {
  94. get { return this.BackColor; }
  95. set
  96. {
  97. this.BackColor = value;
  98. }
  99. }
  100. /// <summary>
  101. /// Gets or sets the color of the item fore.
  102. /// </summary>
  103. /// <value>The color of the item fore.</value>
  104. [Description("标题文本色"), Category("自定义")]
  105. public Color ItemForeColor
  106. {
  107. get { return label1.ForeColor; }
  108. set { label1.ForeColor = value; }
  109. }
  110. /// <summary>
  111. /// Gets or sets the item fore color2.
  112. /// </summary>
  113. /// <value>The item fore color2.</value>
  114. [Description("副标题文本色"), Category("自定义")]
  115. public Color ItemForeColor2
  116. {
  117. get { return label3.ForeColor; }
  118. set { label3.ForeColor = value; }
  119. }
  120. /// <summary>
  121. /// Gets or sets a value indicating whether [show more BTN].
  122. /// </summary>
  123. /// <value><c>true</c> if [show more BTN]; otherwise, <c>false</c>.</value>
  124. [Description("是否显示右侧更多箭头"), Category("自定义")]
  125. public bool ShowMoreBtn
  126. {
  127. get { return label2.Visible; }
  128. set { label2.Visible = value; ; }
  129. }
  130. /// <summary>
  131. /// Occurs when [item click].
  132. /// </summary>
  133. [Description("项选中事件"), Category("自定义")]
  134. public event EventHandler ItemClick;
  135. /// <summary>
  136. /// 数据源
  137. /// </summary>
  138. /// <value>The data source.</value>
  139. public ListEntity DataSource { get; private set; }
  140. [Description("分割线颜色"), Category("自定义")]
  141. public Color SplitColor
  142. {
  143. get { return this.splitLine_H1.BackColor; }
  144. set { this.splitLine_H1.BackColor = value; }
  145. }
  146. /// <summary>
  147. /// Initializes a new instance of the <see cref="UCListItemExt" /> class.
  148. /// </summary>
  149. public UCListItemExt()
  150. {
  151. InitializeComponent();
  152. SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
  153. this.UpdateStyles();
  154. }
  155. /// <summary>
  156. /// Handles the MouseDown event of the item control.
  157. /// </summary>
  158. /// <param name="sender">The source of the event.</param>
  159. /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
  160. private void item_MouseDown(object sender, MouseEventArgs e)
  161. {
  162. if (ItemClick != null)
  163. {
  164. ItemClick(this, e);
  165. }
  166. }
  167. #region 设置数据
  168. /// <summary>
  169. /// 功能描述:设置数据
  170. /// 作  者:HZH
  171. /// 创建日期:2019-02-27 11:52:52
  172. /// 任务编号:POS
  173. /// </summary>
  174. /// <param name="data">data</param>
  175. public void SetData(ListEntity data)
  176. {
  177. this.Title = data.Title;
  178. this.Title2 = data.Title2;
  179. this.ShowMoreBtn = data.ShowMoreBtn;
  180. DataSource = data;
  181. }
  182. #endregion
  183. }
  184. }