基础
2025/4/3原创小于 1 分钟约 146 字
1. 自定义控件属性
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BHG.POS
{
public partial class UserPanel : UserControl, INotifyPropertyChanged
{
public event EventHandler PanelClick;
public event PropertyChangedEventHandler PropertyChanged;
public UserPanel()
{
InitializeComponent();
}
protected virtual void OnPanelClick(EventArgs e)
{
PanelClick?.Invoke(this, e);
}
private Color _buttonColor = Color.Blue; // 默认颜色
[Category("Appearance")]
[Description("The color of the button")]
public Color ButtonColor
{
get { return _buttonColor; }
set
{
_buttonColor = value;
this.BackColor = _buttonColor;
//OnPropertyChanged(nameof(ButtonColor));
this.Invalidate(); // 触发重绘
}
}
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}