如何更改禁用控件的样式?

soo*_*ise 3 c# winforms

当一个WinForm元素被禁用时,它会变灰.是否可以禁用元素,但调整禁用的样式以使其仍然显示为启用(不显示为灰色)?

Han*_*ant 5

防止可聚焦控制成为焦点需要采取一些对策.您将必须包含一个控件,该控件确实将此类的重点放在所有尝试上:

using System;
using System.Windows.Forms;

class RichLabel : RichTextBox {
    public RichLabel() {
        this.ReadOnly = true;
        this.TabStop = false;
        this.SetStyle(ControlStyles.Selectable, false);
    }
    protected override void OnEnter(EventArgs e) {
        if (!DesignMode) this.Parent.SelectNextControl(this, true, true, true, true);
        base.OnEnter(e);
    }
    protected override void WndProc(ref Message m) {
        if (m.Msg < 0x201 || m.Msg > 0x20e)
            base.WndProc(ref m);
    }
}
Run Code Online (Sandbox Code Playgroud)