如何更改富文本框的背景颜色,当它被禁用? [英] How to change the background color of a rich text box when it is disabled?

查看:2240
本文介绍了如何更改富文本框的背景颜色,当它被禁用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我设置了 RichTextBox.Enabled 属性设置为false,它的背景色自动设置为灰色,因为它被设置为系统颜色的颜色,这是在设置控制面板。我怎样才能改变其颜色为黑色,即使我将它设置为禁用?

Whenever I set the RichTextBox.Enabled property to false, its background color is automatically set to gray as it is set to the color in system color which is set in the control panel. How can I change its color to black even if I set it to disabled?

推荐答案

请参阅:<一href="http://stackoverflow.com/questions/276179/how-to-change-the-font-color-of-a-disabled-textbox">http://stackoverflow.com/questions/276179/how-to-change-the-font-color-of-a-disabled-textbox

richTextBox.TabStop = false;
richTextBox.ReadOnly = true;
richTextBox.BackColor = Color.DimGray;
richTextBox.Cursor = Cursors.Arrow;
richTextBox.Enter += richTextBox_Enter;

private void richTextBox_Enter(object sender, EventArgs e)
{
    // you need to set the focus somewhere else. Eg a label.
    SomeOtherControl.Focus();
}

或连接扩展方法(我意识到你没有把它只读,因为Enter事件捕获任何输入):

or as en extension method (I realized you don't have to put it in readonly since the Enter event catches any input):

public static class MyExtensions
{
    public static void Disable( this Control control, Control focusTarget )
    {
        control.TabStop = false;
        control.BackColor = Color.DimGray;
        control.Cursor = Cursors.Arrow;
        control.Enter += delegate { focusTarget.Focus(); };
    }
}

这篇关于如何更改富文本框的背景颜色,当它被禁用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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