473,395 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

In C#, When set property 'Enabled' to 'false', the text background turn to gray How to prevent it?
Mar 23 '07 #1
10 13231
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
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
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
807 Expert 512MB
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
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
807 Expert 512MB
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
Sam: I appreciate what you recommended, By override, the problem has been fixed. Thank you so much
Mar 26 '07 #8
SammyB
807 Expert 512MB
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
Sam, It's OnEnabledChanged
Mar 26 '07 #10
Jamescd Can u explain clearly how u solved that rtb backround dull to normal color
Dec 31 '19 #11

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

Similar topics

0
by: Dean | last post by:
Printing content of RichTextBox (as described here (in C#) http://support.microsoft.com/default.aspx?scid=kb;en-us;812425) results in white background of the text printed. Is there any way of...
2
by: michael_quinlivan | last post by:
Hi all, I have noticed that the background color of an XML document cannot be set properly using CSS (that is, you cannot define styles for the BODY element of an XHTML document). I have an...
0
by: Leitgeb | last post by:
RichText has 2 properties for setting text color and text. RichTextBox.SelectionColor = Color.Black ; RichTextBox.SelectionText = "Hello World" ; How do I set yello color background for...
13
by: Rich | last post by:
Hello, So I would like to disable a textbox on a vb.net form without the text getting grayed out. In vb6 I could place a textbox control on a frame control and disable the frame leaving the...
3
by: njuneardave | last post by:
Hey! One quick question: It's really easy to change the background color of an entire RTB, but I have looked and looked and can't find a way to change the background color of the selected text...
4
by: Chris | last post by:
Hello, I have two div's, div1 is a lot bigger and is the parent of div2, and div1 also has a background image. What I would like to do, is set a background color for the smaller nested div2,...
0
by: dvestal | last post by:
I'm creating a simple text editor for an in-house application. Ordinarily, I'd slap a textbox onto a form and call it done, but for various reasons, I'll have to implement this one from scratch. ...
1
by: anmcafresher | last post by:
Hi Guys, I am working with an option where I do want to print a background image without enabling the "Print Background Color and Image" in the IE. I do want to get this image printed on each...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.