You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.6 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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);
}
}
}