|
|
using System;
|
|
|
using System.ComponentModel;
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
namespace CompressorXN_ControlLib
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// DefaultEvent特性是在引用该自定义控件的控件中双击自定义控件时,自动生成Click方法
|
|
|
/// </summary>
|
|
|
[DefaultEvent("Click")]
|
|
|
public partial class NaviButton : UserControl
|
|
|
{
|
|
|
public NaviButton()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
|
|
|
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
|
|
this.SetStyle(ControlStyles.DoubleBuffer, true);
|
|
|
this.SetStyle(ControlStyles.ResizeRedraw, true);
|
|
|
this.SetStyle(ControlStyles.Selectable, true);
|
|
|
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
|
|
|
}
|
|
|
|
|
|
|
|
|
private bool isSelected = false;
|
|
|
[Browsable(true)]
|
|
|
[Category("自定义属性")]
|
|
|
[Description("设置或显示导航按钮是否选中")]
|
|
|
public bool IsSelected
|
|
|
{
|
|
|
get { return isSelected; }
|
|
|
set
|
|
|
{
|
|
|
isSelected = value;
|
|
|
UpdateImg();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private bool isLeft = true;
|
|
|
[Browsable(true)]
|
|
|
[Category("自定义属性")]
|
|
|
[Description("设置或显示导航按钮是否为左边")]
|
|
|
public bool IsLeft
|
|
|
{
|
|
|
get { return isLeft; }
|
|
|
set
|
|
|
{
|
|
|
isLeft = value;
|
|
|
UpdateImg();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private string titleName = "导航按钮";
|
|
|
[Browsable(true)]
|
|
|
[Category("自定义属性")]
|
|
|
[Description("设置或显示导航按钮的文本内容")]
|
|
|
public string TitleName
|
|
|
{
|
|
|
get { return titleName; }
|
|
|
set
|
|
|
{
|
|
|
titleName = value;
|
|
|
lbl_Title.Text = titleName;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新背景
|
|
|
/// </summary>
|
|
|
private void UpdateImg()
|
|
|
{
|
|
|
if (this.IsLeft)
|
|
|
{
|
|
|
this.BackgroundImage = IsSelected ? Properties.Resources.LeftSelected : Properties.Resources.LeftUnSelected;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.BackgroundImage = IsSelected ? Properties.Resources.RightSelected : Properties.Resources.RightUnSelected;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
[Browsable(true)]
|
|
|
[Category("自定义事件")]
|
|
|
[Description("设置或显示导航按钮的单击事件")]
|
|
|
public new EventHandler Click;
|
|
|
|
|
|
private void lbl_Title_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
this.Click?.Invoke(this, e);
|
|
|
}
|
|
|
}
|
|
|
}
|