PC Review


Reply
Thread Tools Rate Thread

Disabled Control Font Colour change?

 
 
Bob
Guest
Posts: n/a
 
      25th Aug 2006
Hi,
Is it possible to change the forecolor of a disabled text control.
I have a RichText Box that I don't want the user to edit but the Grey on
Grey default is hard to read.
Is there a way of overriding this with a custom colour?
I had a quick foray into the forms Paint event handler but no joy.
Thanks
Bob


 
Reply With Quote
 
 
 
 
Bruce Wood
Guest
Posts: n/a
 
      25th Aug 2006

Bob wrote:
> Hi,
> Is it possible to change the forecolor of a disabled text control.
> I have a RichText Box that I don't want the user to edit but the Grey on
> Grey default is hard to read.
> Is there a way of overriding this with a custom colour?
> I had a quick foray into the forms Paint event handler but no joy.
> Thanks
> Bob


Well, TextBox has a ReadOnly property, which sounds like exactly what
you want. Unfortunately, RichTextBox doesn't have ReadOnly.

I solved this problem for ComboBox by creating my own

public class ComboBoxWithReadOnly : ComboBox

and then adding the new property, along with the appropriate code to
intercept keypresses, pastes, and cuts if ReadOnly is true. The
advantage of this approach, as well, is that the user is still free to
Copy text from the control (which they couldn't do if it were
disabled)... they just can't change it.

BTW, this approach is also useful for ListViews and the like, for which
the disabled control (stupidly) can't be scrolled. So if you want your
user to be able to scroll and see everything inside the control but
don't want to allow changes, disabling the control is a non-starter.

 
Reply With Quote
 
Bob
Guest
Posts: n/a
 
      25th Aug 2006
Hi Bruce,
Thank you.
Didn't realise disabling killed scrolling.
Pull up! PullUp!
Shall go the intercept way.
Regards
Bob
"Bruce Wood" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Bob wrote:
> > Hi,
> > Is it possible to change the forecolor of a disabled text control.
> > I have a RichText Box that I don't want the user to edit but the Grey on
> > Grey default is hard to read.
> > Is there a way of overriding this with a custom colour?
> > I had a quick foray into the forms Paint event handler but no joy.
> > Thanks
> > Bob

>
> Well, TextBox has a ReadOnly property, which sounds like exactly what
> you want. Unfortunately, RichTextBox doesn't have ReadOnly.
>
> I solved this problem for ComboBox by creating my own
>
> public class ComboBoxWithReadOnly : ComboBox
>
> and then adding the new property, along with the appropriate code to
> intercept keypresses, pastes, and cuts if ReadOnly is true. The
> advantage of this approach, as well, is that the user is still free to
> Copy text from the control (which they couldn't do if it were
> disabled)... they just can't change it.
>
> BTW, this approach is also useful for ListViews and the like, for which
> the disabled control (stupidly) can't be scrolled. So if you want your
> user to be able to scroll and see everything inside the control but
> don't want to allow changes, disabling the control is a non-starter.
>



 
Reply With Quote
 
Bob
Guest
Posts: n/a
 
      25th Aug 2006
Hi Bruce,
Turns out that the rtb does have a readonly property!

regards
bob
"Bruce Wood" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Bob wrote:
> > Hi,
> > Is it possible to change the forecolor of a disabled text control.
> > I have a RichText Box that I don't want the user to edit but the Grey on
> > Grey default is hard to read.
> > Is there a way of overriding this with a custom colour?
> > I had a quick foray into the forms Paint event handler but no joy.
> > Thanks
> > Bob

>
> Well, TextBox has a ReadOnly property, which sounds like exactly what
> you want. Unfortunately, RichTextBox doesn't have ReadOnly.
>
> I solved this problem for ComboBox by creating my own
>
> public class ComboBoxWithReadOnly : ComboBox
>
> and then adding the new property, along with the appropriate code to
> intercept keypresses, pastes, and cuts if ReadOnly is true. The
> advantage of this approach, as well, is that the user is still free to
> Copy text from the control (which they couldn't do if it were
> disabled)... they just can't change it.
>
> BTW, this approach is also useful for ListViews and the like, for which
> the disabled control (stupidly) can't be scrolled. So if you want your
> user to be able to scroll and see everything inside the control but
> don't want to allow changes, disabling the control is a non-starter.
>



 
Reply With Quote
 
Bruce Wood
Guest
Posts: n/a
 
      25th Aug 2006

Bob wrote:
> Hi Bruce,
> Turns out that the rtb does have a readonly property!
>
> regards
> bob


Gosh darn. Now why didn't I see that in my local Visual Studio help...?

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
change back colour when form is enabled/disabled =?Utf-8?B?c2N1YmFkaXZlcg==?= Microsoft Access Forms 0 20th Feb 2007 12:01 PM
Change the colour of the disabled state of a control? garyusenet@myway.com Microsoft C# .NET 5 8th Jan 2007 03:52 PM
change colour of disabled textbox text =?Utf-8?B?QmFzaWw=?= Microsoft Excel Programming 0 25th Aug 2005 06:21 PM
HowTo:Change disabled control font color? =?Utf-8?B?c3Ryb3V0?= Microsoft Dot NET Framework Forms 6 24th Jan 2005 10:55 PM
font colour for disabled or read only textbox =?Utf-8?B?YW1iZXI=?= Microsoft Dot NET 3 12th Oct 2004 04:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:23 PM.