C# 如何重写userControl属性
IDE:C.net、WINFORMS、.NET4.0 Hi已经创建了一个userControl,我想创建一个属性,如果启用的user control为false,则将back Image更改为imgDisabled.jpg else imgEnabled.jpg 请告诉我如何覆盖usercontrol的Enabled属性并将此函数添加到其中C# 如何重写userControl属性,c#,winforms,user-controls,C#,Winforms,User Controls,IDE:C.net、WINFORMS、.NET4.0 Hi已经创建了一个userControl,我想创建一个属性,如果启用的user control为false,则将back Image更改为imgDisabled.jpg else imgEnabled.jpg 请告诉我如何覆盖usercontrol的Enabled属性并将此函数添加到其中 private void onPropertyChanged() { if (this.Enabled)
private void onPropertyChanged()
{
if (this.Enabled)
this.BackgroundImage = Properties.Resources.imgEnabled;
else
this.BackgroundImage = Properties.Resources.imgDisabled;
}
重写基本控件类的虚拟OnEnabledChanged方法:
请使用像这样的活动litner 类CustomProperty:Property { 公共事件处理程序选择已更改
private int _selectionStart;
private int _selectionLength;
protected override void OnMouseDown(MouseEventArgs e)
{
_selectionStart = SelectionStart;
_selectionLength = SelectionLength;
base.OnMouseDown(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
if (null != SelectionChanged && (_selectionStart != SelectionStart || _selectionLength != SelectionLength))
SelectionChanged(this, EventArgs.Empty);
base.OnMouseUp(e);
}
}
private int _selectionStart;
private int _selectionLength;
protected override void OnMouseDown(MouseEventArgs e)
{
_selectionStart = SelectionStart;
_selectionLength = SelectionLength;
base.OnMouseDown(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
if (null != SelectionChanged && (_selectionStart != SelectionStart || _selectionLength != SelectionLength))
SelectionChanged(this, EventArgs.Empty);
base.OnMouseUp(e);
}