// ***********************************************************************
// Assembly : HZH_Controls
// Created : 08-15-2019
//
// ***********************************************************************
//
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
//
//
// Blog: https://www.cnblogs.com/bfyx
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
//
// If you use this code, please keep this note.
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace HZH_Controls.Controls
{
///
/// 父类节点
/// Implements the
/// Implements the
///
///
///
[ToolboxItem(false)]
public partial class UCMenuParentItem : UserControl, IMenuItem
{
///
/// Occurs when [selected item].
///
public event EventHandler SelectedItem;
///
/// The m data source
///
private MenuItemEntity m_dataSource;
///
/// Gets or sets the data source.
///
/// The data source.
public MenuItemEntity DataSource
{
get
{
return m_dataSource;
}
set
{
m_dataSource = value;
if (value != null)
{
lblTitle.Text = value.Text;
}
}
}
///
/// Initializes a new instance of the class.
///
public UCMenuParentItem()
{
InitializeComponent();
lblTitle.MouseDown += lblTitle_MouseDown;
}
///
/// 设置样式
///
/// key:属性名称,value:属性值
/// 菜单元素设置样式异常
/// 菜单元素设置样式异常
public void SetStyle(Dictionary styles)
{
Type t = this.GetType();
foreach (var item in styles)
{
var pro = t.GetProperty(item.Key);
if (pro != null && pro.CanWrite)
{
try
{
pro.SetValue(this, item.Value, null);
}
catch (Exception ex)
{
throw new Exception("菜单元素设置样式异常", ex);
}
}
}
}
///
/// 设置选中样式
///
/// 是否选中
public void SetSelectedStyle(bool? blnSelected)
{
if (blnSelected.HasValue)
{
if (blnSelected.Value)
{
this.lblTitle.Image = Properties.Resources.sanjiao1;
}
else
{
this.lblTitle.Image = Properties.Resources.sanjiao2;
}
}
else
{
this.lblTitle.Image = null;
}
}
///
/// Handles the MouseDown event of the lblTitle control.
///
/// The source of the event.
/// The instance containing the event data.
void lblTitle_MouseDown(object sender, MouseEventArgs e)
{
if (SelectedItem != null)
{
SelectedItem(this, e);
}
}
}
}