当 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/