OnEnabledChanged 无法为按钮设置 Backcolor Disable

OnEnabledChanged can't set Backcolor Disable for button

这是代码示例

 public partial class ColorButton: Button
{
     protected override void OnEnabledChanged(EventArgs e)
            {
                if (this.Enabled)
                {
                    this.BackColor = this.BackColorEnable;              
                }
                else
                {
                    this.BackColor = Color.Gray;
                }
                base.OnEnabledChanged(e);
                
            }

    pubic void ColorSet()
    {
            if (BaseColor == Blue)
                {
                   this.BackColor = Color.Blue;
                }
            if (BaseColor == Red)
                {
                   this.BackColor = Color.Red;
                }
            if (BaseColor == Yellow)
                {
                   this.BackColor = Color.Yellow;
                }
    }
}

按钮将在另一个屏幕上自动着色并且 btn.enable = flase;还调整了红色、黄色、绿色。我希望按钮 'btn.enable = flase;' 必须是灰色的。有人有什么想法吗?

在此处更改代码

public void ColorSet()
{
    if (BaseColor == Blue)
    {
        if(this.Enable)
        {
            this.BackColor = Color.Blue;
        }
        else
        {
            this.BackColor = Color.Gray;
        }
    }
    if (BaseColor == Red)
    {
        if(this.Enable)
        {
            this.BackColor = Color.Red;
        }
        else
        {
            this.BackColor = Color.Gray;
        }
    }
    if (BaseColor == Yellow)
    {
        if(this.Enable)
        {
            this.BackColor = Color.Yellow;
        }
        else
        {
            this.BackColor = Color.Gray;
        }
    }
}

我认为 OnEnabledChanged 函数并没有真正完成它的工作,所以只需将 if(this.Enable) 条件放入即可。