By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,500 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

How to disable RichTextBox without it's text background color fading

P: 5
In C#, When set property 'Enabled' to 'false', the text background turn to gray How to prevent it?
Mar 23 '07 #1
Share this Question
Share on Google+
10 Replies


P: 4
Set the

BackColor = SystemColors.ControlLightLight;


That will fix the backcolor. I also recommend to put:

Enable = True
ReadOnly = True


This will allow you to select the text and move the scrollbars (when necessary).
Mar 23 '07 #2

P: 5
Thanks, oarrocha

I want RichTextBox:
1. do not respond to user interaction
2. keep original Forecolor and Backcolor

After "Enabled = false", "BackColor = SystemColors.ControlLightLight" will not work anymore.
Mar 24 '07 #3

P: 4
Thanks, oarrocha

I want RichTextBox:
1. do not respond to user interaction
2. keep original Forecolor and Backcolor

After "Enabled = false", "BackColor = SystemColors.ControlLightLight" will not work anymore.
You are right... with Enabled = false, it won't work as you want it.

Here is an example, where I dropped a RichTextBox and a Button, and set the button1.Click Event and richTextVBox1.Enter with this code:
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.BackColor = SystemColors.ControlLightLight;
richTextBox1.ReadOnly = !richTextBox1.ReadOnly;
}
private void richTextBox1_Enter(object sender, EventArgs e)
{
RichTextBox obj = (RichTextBox)sender;
if (obj.ReadOnly) GetNextControl(obj, true).Focus();
}

If the richtextbox doesn't has scrollbars, it works like you want it, otherwise, the user has control of the scroll bars
Mar 24 '07 #4

SammyB
Expert 100+
P: 807
Thanks, oarrocha

I want RichTextBox:
1. do not respond to user interaction
2. keep original Forecolor and Backcolor

After "Enabled = false", "BackColor = SystemColors.ControlLightLight" will not work anymore.
I think that you should go with ReadOnly=True. Then you can save the current background and restore it afterwards.
Expand|Select|Wrap|Line Numbers
  1.         Dim saveColor As Color
  2.         saveColor = RtbEditor.BackColor
  3.         RtbEditor.ReadOnly = True
  4.         RtbEditor.BackColor = saveColor
It's strange that ReadOnly and Enable behave differently. You might also create a control derived from the RTB & override whatever causes the grey. Good luck.
Mar 24 '07 #5

P: 5
oarrocha, SammyB, Thank you guys.

There may be a little misunderstanding. Actually, I want the RichTextBox to be inactive, ie. doesn't control the area where it is; doesn't get focus; keep this original forecolor and backcolor. I used "Enabled=false", but the backcolor .....
Mar 24 '07 #6

SammyB
Expert 100+
P: 807
oarrocha, SammyB, Thank you guys.

There may be a little misunderstanding. Actually, I want the RichTextBox to be inactive, ie. doesn't control the area where it is; doesn't get focus; keep this original forecolor and backcolor. I used "Enabled=false", but the backcolor .....
I think we understood what you wanted, but without creating a custom control, we were unable to do it. However, Oarrocha discovered it was possible with ReadOnly. The little bit gained with Enable just doesn't seem worth the pain of writing a custom control. --Sam
Mar 25 '07 #7

P: 5
Sam: I appreciate what you recommended, By override, the problem has been fixed. Thank you so much
Mar 26 '07 #8

SammyB
Expert 100+
P: 807
Sam: I appreciate what you recommended, By override, the problem has been fixed. Thank you so much
Wow! I'm impressed! What did you have to overide?
Mar 26 '07 #9

P: 5
Sam, It's OnEnabledChanged
Mar 26 '07 #10

P: 1
Jamescd Can u explain clearly how u solved that rtb backround dull to normal color
3 Weeks Ago #11

Post your reply

Sign in to post your reply or Sign up for a free account.