UCListViewItem.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // ***********************************************************************
  2. // Assembly : HZH_Controls
  3. // Created : 08-22-2019
  4. //
  5. // ***********************************************************************
  6. // <copyright file="UCListViewItem.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 UCListViewItem.
  28. /// Implements the <see cref="HZH_Controls.Controls.UCControlBase" />
  29. /// Implements the <see cref="HZH_Controls.Controls.IListViewItem" />
  30. /// </summary>
  31. /// <seealso cref="HZH_Controls.Controls.UCControlBase" />
  32. /// <seealso cref="HZH_Controls.Controls.IListViewItem" />
  33. [ToolboxItem(false)]
  34. public partial class UCListViewItem : UCControlBase, IListViewItem
  35. {
  36. /// <summary>
  37. /// The m data source
  38. /// </summary>
  39. private object m_dataSource;
  40. /// <summary>
  41. /// 数据源
  42. /// </summary>
  43. /// <value>The data source.</value>
  44. public object DataSource
  45. {
  46. get
  47. {
  48. return m_dataSource;
  49. }
  50. set
  51. {
  52. m_dataSource = value;
  53. lblTitle.Text = value.ToString();
  54. }
  55. }
  56. /// <summary>
  57. /// 选中项事件
  58. /// </summary>
  59. public event EventHandler SelectedItemEvent;
  60. /// <summary>
  61. /// Initializes a new instance of the <see cref="UCListViewItem" /> class.
  62. /// </summary>
  63. public UCListViewItem()
  64. {
  65. InitializeComponent();
  66. lblTitle.MouseDown += lblTitle_MouseDown;
  67. }
  68. /// <summary>
  69. /// Handles the MouseDown event of the lblTitle control.
  70. /// </summary>
  71. /// <param name="sender">The source of the event.</param>
  72. /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
  73. void lblTitle_MouseDown(object sender, MouseEventArgs e)
  74. {
  75. if (SelectedItemEvent != null)
  76. {
  77. SelectedItemEvent(this, e);
  78. }
  79. }
  80. /// <summary>
  81. /// Sets the selected.
  82. /// </summary>
  83. /// <param name="blnSelected">if set to <c>true</c> [BLN selected].</param>
  84. public void SetSelected(bool blnSelected)
  85. {
  86. if (blnSelected)
  87. this.FillColor = Color.FromArgb(255, 247, 245);
  88. else
  89. this.FillColor = Color.White;
  90. this.Refresh();
  91. }
  92. }
  93. }