UCMenuChildrenItem.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // ***********************************************************************
  2. // Assembly : HZH_Controls
  3. // Created : 08-15-2019
  4. //
  5. // ***********************************************************************
  6. // <copyright file="UCMenuChildrenItem.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. /// 子类节点
  28. /// Implements the <see cref="System.Windows.Forms.UserControl" />
  29. /// Implements the <see cref="HZH_Controls.Controls.IMenuItem" />
  30. /// </summary>
  31. /// <seealso cref="System.Windows.Forms.UserControl" />
  32. /// <seealso cref="HZH_Controls.Controls.IMenuItem" />
  33. [ToolboxItem(false)]
  34. public partial class UCMenuChildrenItem : UserControl, IMenuItem
  35. {
  36. /// <summary>
  37. /// Occurs when [selected item].
  38. /// </summary>
  39. public event EventHandler SelectedItem;
  40. /// <summary>
  41. /// The m data source
  42. /// </summary>
  43. private MenuItemEntity m_dataSource;
  44. /// <summary>
  45. /// Gets or sets the data source.
  46. /// </summary>
  47. /// <value>The data source.</value>
  48. public MenuItemEntity DataSource
  49. {
  50. get
  51. {
  52. return m_dataSource;
  53. }
  54. set
  55. {
  56. m_dataSource = value;
  57. if (value != null)
  58. {
  59. lblTitle.Text = value.Text;
  60. }
  61. }
  62. }
  63. /// <summary>
  64. /// Initializes a new instance of the <see cref="UCMenuChildrenItem" /> class.
  65. /// </summary>
  66. public UCMenuChildrenItem()
  67. {
  68. InitializeComponent();
  69. this.lblTitle.MouseDown += lblTitle_MouseDown;
  70. }
  71. /// <summary>
  72. /// Handles the MouseDown event of the lblTitle control.
  73. /// </summary>
  74. /// <param name="sender">The source of the event.</param>
  75. /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
  76. void lblTitle_MouseDown(object sender, MouseEventArgs e)
  77. {
  78. if (SelectedItem != null)
  79. {
  80. SelectedItem(this, null);
  81. }
  82. }
  83. /// <summary>
  84. /// 设置样式
  85. /// </summary>
  86. /// <param name="styles">key:属性名称,value:属性值</param>
  87. /// <exception cref="System.Exception">菜单元素设置样式异常</exception>
  88. /// <exception cref="Exception">菜单元素设置样式异常</exception>
  89. public void SetStyle(Dictionary<string, object> styles)
  90. {
  91. Type t = this.GetType();
  92. foreach (var item in styles)
  93. {
  94. var pro = t.GetProperty(item.Key);
  95. if (pro != null && pro.CanWrite)
  96. {
  97. try
  98. {
  99. pro.SetValue(this, item.Value, null);
  100. }
  101. catch (Exception ex)
  102. {
  103. throw new Exception("菜单元素设置样式异常", ex);
  104. }
  105. }
  106. }
  107. }
  108. /// <summary>
  109. /// Sets the selected style.
  110. /// </summary>
  111. /// <param name="blnSelected">if set to <c>true</c> [BLN selected].</param>
  112. public void SetSelectedStyle(bool? blnSelected)
  113. {
  114. }
  115. }
  116. }