如何更改禁用控件的样式? [英] How do I change the style of a disabled control?

查看:67
本文介绍了如何更改禁用控件的样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

禁用WinForm元素后,它会变灰.是否可以禁用某个元素,但可以调整禁用的样式,使其看起来仍然处于启用状态(而不是变灰)?

When a WinForm element is disabled, it sort of grays out. Is it possible to disable an element, but adjust the disabled style so it still looks enabled (not grayed out)?

推荐答案

要防止焦点集中的控件获得焦点,需要采取许多对策.您将必须包含一个确实做为该类的控件的控件,以抵抗所有尝试:

Preventing a focusable control from taking the focus takes a number of counter-measures. You will have to include a control that does take the focus for this class to be resist all attempts:

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

这篇关于如何更改禁用控件的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆