[DefaultEvent("Click")]
public partial class UPageButton : UserControl
{
public UPageButton()
{
InitializeComponent();
}
/// <summary>
/// 按钮文本
/// </summary>
public string BtnText
{
get { return lblText.Text; }
set { lblText.Text = value; }
}
public override Color ForeColor { get => lblText.ForeColor; set => lblText.ForeColor = value; }
protected override void OnClick(EventArgs e)
{
lblText.ForeColor = Color.FromArgb(45, 50, 116);
base.OnClick(e);
}
private void lblText_Click(object sender, EventArgs e)
{
this.OnClick(e);
}
}
2021-05-21 仓库温控系统(Winform) 16 扩展控件-PageButton
这篇博客介绍了如何创建一个名为UPageButton的自定义用户控件,该控件继承自UserControl。控件包含了按钮文本属性BtnText,允许设置和获取按钮文字,并且覆写了ForeColor属性以改变文字颜色。在点击事件处理中,BtnText的颜色会变为特定的RGB值。此外,控件还监听lblText_Click事件,触发时同样调用OnClick方法,确保事件处理的一致性。
8420





