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

标签 c# winforms

当 WinForm 元素被禁用时,它会变灰。是否可以禁用一个元素,但调整禁用的样式使其看起来仍然启用(而不是变灰)?

最佳答案

要防止可聚焦控件获得焦点,需要采取多种对策。您必须包含一个控件,该控件确实使该类获得焦点以抵制所有尝试:

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);
    }
}

关于c# - 如何更改禁用控件的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3805545/

相关文章:

C# - 将变量编译为名称/代码

C# 线程 - 父访问问题

c# - 许多系列的图表控件宽度

c# - 如何以编程方式使用 C# 从 BitBucket 中提取代码

C# WinForms 用鼠标拖动控件

c# - 从 toolStripComboBox 检索值

c# - 在调试时序列化并打印对象的整个状态

c# - 如何使用 ASP.NET 跟踪下载?

c# - IComparable<T>.CompareTo() 返回值?

C#:System.Windows.Forms.DataVisualization.Charting.Chart 设置线宽