Files
1257B_DB/JinYuan.ControlLib/NaviButton.cs
T
2026-08-06 09:23:30 +08:00

91 lines
2.6 KiB
C#

using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace JinYuan.ControlLib
{
[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;
UpdataImage();
}
}
private bool isLeft = true;
[Browsable(true)]//是否可见
[Category("自定义属性")] //类别
[Description("设置或显示导航按钮是否为左边")]
public bool IsLeft
{
get { return isLeft; }
set
{
isLeft = value;
UpdataImage();
}
}
private string titleName = "导航按钮";
[Browsable(true)]//是否可见
[Category("自定义属性")] //类别
[Description("设置或显示导航按钮文本内容")]
public string TitleName
{
get { return titleName; }
set
{
titleName = value;
this.lbl_Title.Text = titleName;
}
}
/// <summary>
///统一更新背景
/// </summary>
private void UpdataImage()
{
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);
}
}
}