简体   繁体   中英

How to change the fore color of a disabled multiline TextBox?

I have a multiline Text Box. How can I change the fore color when it is disabled ?

I fond a solution here Change a textbox colour when disabled C#

But, when MultiLine is true, it is a little bit complicated to find out currently visible portion of the text (ie currently visible lines and characters).

So any one know how to play with WM_CTLCOLOREDIT and WM_CTLCOLORSTATIC messages to change the fore color of Text Box in C#.NET ? OR How to change the fore color of a disabled Text Box without overriding

OnPaint()    

method ?

instead of using enbled property of textbox why dont you use keypress event

private bool isDisabled = false;

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (isDisabled == true)
        {
            e.KeyChar = (char)0;
        }

    }

you can change the fore color everytime isDisable = true

Hope it Helps

You can either do:

richTextBox1.ForeColor = System.Drawing.Color.Red

or if you want to use black color, you have to use this trick:

richTextBox1.ForeColor = System.Drawing.Color.FromArgb(0,0,0);

Why don't you make it simple?

Keep the textBox enabled, and set both foreground and background colors as you want them. And if you want that the user can not focus it, then use the event textBox.Focused to detect its focusing, as the event raises, set any other control to focus by programming.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM