PC Review


Reply
Thread Tools Rate Thread

Change the colour of the disabled state of a control?

 
 
garyusenet@myway.com
Guest
Posts: n/a
 
      5th Jan 2007
I'm using krypton toolkit which has allowed me to make a cool looking
form. However, when I set my textbox to disabled it is 'greyed' out.
The grey colour isn't in keeping with the office 2007 style look of my
form. How can i change the colour that control assumed when it's
disabled?

Thanks!

Gary-

 
Reply With Quote
 
 
 
 
Fabrizio Romano
Guest
Posts: n/a
 
      5th Jan 2007
My first guess would be doing something like that:

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public class CustomDisabledTextBox : System.Windows.Forms.TextBox{

Color disabledBackColor, originalBackColor;

public CustomDisabledTextBox() {
disabledBackColor = Color.LightBlue; // or whatever you like
}

protected override void OnEnabledChanged(EventArgs e) {
if (!this.Enabled) {
this.originalBackColor = this.BackColor;
this.BackColor = disabledBackColor;
} else {
this.BackColor = originalBackColor;
}
base.OnEnabledChanged(e);
}

[Browsable(true)]
public Color DisabledBackColor {
get {
return this.disabledBackColor;
}
set {
this.disabledBackColor = value;
}
}

}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

And use this textbox.
When the Enable state changes in the overridden method you place the desired
color. If the control is disabled you place yours, otherwise the original
one.
Also, adding the property accessor with the [Browsable(true)] attribute
let's you define the disabled back color at design time.

Done in 2 minutes so don't take this at 100% best solution ok?
Regards
Fabrizio

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm using krypton toolkit which has allowed me to make a cool looking
> form. However, when I set my textbox to disabled it is 'greyed' out.
> The grey colour isn't in keeping with the office 2007 style look of my
> form. How can i change the colour that control assumed when it's
> disabled?
>
> Thanks!
>
> Gary-
>



 
Reply With Quote
 
Eric Moreau
Guest
Posts: n/a
 
      8th Jan 2007
Your BackColor implementation is working correctly but the ForeColor isn't.
It has always been the problem of disabled controls.

--


HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
S2i web inc. (www.s2i.com)
http://emoreau.s2i.com/

"Fabrizio Romano" <(E-Mail Removed)> wrote in message
news:45a190a8$0$19101$(E-Mail Removed)...
> Well, I suppose he could just do the same for the ForeColor as what I did
> for the BackColor.
> I really had 2 minutes so I just showed the trick with one color.
>
> Regards,
> Fabrizio
>
> "Eric Moreau" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> What about the ForeColor?
>>
>> --
>>
>>
>> HTH
>>
>> Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
>> Conseiller Principal / Senior Consultant
>> S2i web inc. (www.s2i.com)
>> http://emoreau.s2i.com/
>>
>> "Fabrizio Romano" <(E-Mail Removed)> wrote in message
>> news:459e955e$0$19100$(E-Mail Removed)...
>>> My first guess would be doing something like that:
>>>
>>> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>>> public class CustomDisabledTextBox : System.Windows.Forms.TextBox{
>>>
>>> Color disabledBackColor, originalBackColor;
>>>
>>> public CustomDisabledTextBox() {
>>> disabledBackColor = Color.LightBlue; // or whatever you like
>>> }
>>>
>>> protected override void OnEnabledChanged(EventArgs e) {
>>> if (!this.Enabled) {
>>> this.originalBackColor = this.BackColor;
>>> this.BackColor = disabledBackColor;
>>> } else {
>>> this.BackColor = originalBackColor;
>>> }
>>> base.OnEnabledChanged(e);
>>> }
>>>
>>> [Browsable(true)]
>>> public Color DisabledBackColor {
>>> get {
>>> return this.disabledBackColor;
>>> }
>>> set {
>>> this.disabledBackColor = value;
>>> }
>>> }
>>>
>>> }
>>> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>>>
>>> And use this textbox.
>>> When the Enable state changes in the overridden method you place the
>>> desired color. If the control is disabled you place yours, otherwise the
>>> original one.
>>> Also, adding the property accessor with the [Browsable(true)] attribute
>>> let's you define the disabled back color at design time.
>>>
>>> Done in 2 minutes so don't take this at 100% best solution ok?
>>> Regards
>>> Fabrizio
>>>
>>> <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> I'm using krypton toolkit which has allowed me to make a cool looking
>>>> form. However, when I set my textbox to disabled it is 'greyed' out.
>>>> The grey colour isn't in keeping with the office 2007 style look of my
>>>> form. How can i change the colour that control assumed when it's
>>>> disabled?
>>>>
>>>> Thanks!
>>>>
>>>> Gary-
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Fabrizio Romano
Guest
Posts: n/a
 
      8th Jan 2007
You're right.
It seems that there is not an easy solution, at least in the first 20/30
results on google and I'm not even talking about msdn...
Maybe he could just do the background trick I suggested setting the ReadOnly
property to false instead of disabling the control.
And if he also wants the control not to be selectable he could just handle
the Enter() event giving the focus to some other control.
What would you suggest?

Regards,
Fabrizio


"Eric Moreau" <(E-Mail Removed)> wrote in message
news:OYu%(E-Mail Removed)...
> Your BackColor implementation is working correctly but the ForeColor
> isn't. It has always been the problem of disabled controls.
>
> --
>
>
> HTH
>
> Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
> Conseiller Principal / Senior Consultant
> S2i web inc. (www.s2i.com)
> http://emoreau.s2i.com/
>
> "Fabrizio Romano" <(E-Mail Removed)> wrote in message
> news:45a190a8$0$19101$(E-Mail Removed)...
>> Well, I suppose he could just do the same for the ForeColor as what I did
>> for the BackColor.
>> I really had 2 minutes so I just showed the trick with one color.
>>
>> Regards,
>> Fabrizio
>>
>> "Eric Moreau" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> What about the ForeColor?
>>>
>>> --
>>>
>>>
>>> HTH
>>>
>>> Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
>>> Conseiller Principal / Senior Consultant
>>> S2i web inc. (www.s2i.com)
>>> http://emoreau.s2i.com/
>>>
>>> "Fabrizio Romano" <(E-Mail Removed)> wrote in message
>>> news:459e955e$0$19100$(E-Mail Removed)...
>>>> My first guess would be doing something like that:
>>>>
>>>> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>>>> public class CustomDisabledTextBox : System.Windows.Forms.TextBox{
>>>>
>>>> Color disabledBackColor, originalBackColor;
>>>>
>>>> public CustomDisabledTextBox() {
>>>> disabledBackColor = Color.LightBlue; // or whatever you like
>>>> }
>>>>
>>>> protected override void OnEnabledChanged(EventArgs e) {
>>>> if (!this.Enabled) {
>>>> this.originalBackColor = this.BackColor;
>>>> this.BackColor = disabledBackColor;
>>>> } else {
>>>> this.BackColor = originalBackColor;
>>>> }
>>>> base.OnEnabledChanged(e);
>>>> }
>>>>
>>>> [Browsable(true)]
>>>> public Color DisabledBackColor {
>>>> get {
>>>> return this.disabledBackColor;
>>>> }
>>>> set {
>>>> this.disabledBackColor = value;
>>>> }
>>>> }
>>>>
>>>> }
>>>> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>>>>
>>>> And use this textbox.
>>>> When the Enable state changes in the overridden method you place the
>>>> desired color. If the control is disabled you place yours, otherwise
>>>> the original one.
>>>> Also, adding the property accessor with the [Browsable(true)] attribute
>>>> let's you define the disabled back color at design time.
>>>>
>>>> Done in 2 minutes so don't take this at 100% best solution ok?
>>>> Regards
>>>> Fabrizio
>>>>
>>>> <(E-Mail Removed)> wrote in message
>>>> news:(E-Mail Removed)...
>>>>> I'm using krypton toolkit which has allowed me to make a cool looking
>>>>> form. However, when I set my textbox to disabled it is 'greyed' out.
>>>>> The grey colour isn't in keeping with the office 2007 style look of my
>>>>> form. How can i change the colour that control assumed when it's
>>>>> disabled?
>>>>>
>>>>> Thanks!
>>>>>
>>>>> Gary-
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
garyusenet@myway.com
Guest
Posts: n/a
 
      8th Jan 2007
I have just had a chance to spot the replies. Thankyou both some ideas
to get me started.
I'm going to have a play with this over the next couple of days. It's a
shame there isn't an easy way to change the colour that the control
assumes when its disabled - I would have thought this was a basic
requirement! But I guess not.

Thanks for the kind help,

Gary.

Fabrizio Romano wrote:

> You're right.
> It seems that there is not an easy solution, at least in the first 20/30
> results on google and I'm not even talking about msdn...
> Maybe he could just do the background trick I suggested setting the ReadOnly
> property to false instead of disabling the control.
> And if he also wants the control not to be selectable he could just handle
> the Enter() event giving the focus to some other control.
> What would you suggest?
>
> Regards,
> Fabrizio
>
>
> "Eric Moreau" <(E-Mail Removed)> wrote in message
> news:OYu%(E-Mail Removed)...
> > Your BackColor implementation is working correctly but the ForeColor
> > isn't. It has always been the problem of disabled controls.
> >
> > --
> >
> >
> > HTH
> >
> > Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
> > Conseiller Principal / Senior Consultant
> > S2i web inc. (www.s2i.com)
> > http://emoreau.s2i.com/
> >
> > "Fabrizio Romano" <(E-Mail Removed)> wrote in message
> > news:45a190a8$0$19101$(E-Mail Removed)...
> >> Well, I suppose he could just do the same for the ForeColor as what I did
> >> for the BackColor.
> >> I really had 2 minutes so I just showed the trick with one color.
> >>
> >> Regards,
> >> Fabrizio
> >>
> >> "Eric Moreau" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >>> What about the ForeColor?
> >>>
> >>> --
> >>>
> >>>
> >>> HTH
> >>>
> >>> Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
> >>> Conseiller Principal / Senior Consultant
> >>> S2i web inc. (www.s2i.com)
> >>> http://emoreau.s2i.com/
> >>>
> >>> "Fabrizio Romano" <(E-Mail Removed)> wrote in message
> >>> news:459e955e$0$19100$(E-Mail Removed)...
> >>>> My first guess would be doing something like that:
> >>>>
> >>>> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> >>>> public class CustomDisabledTextBox : System.Windows.Forms.TextBox{
> >>>>
> >>>> Color disabledBackColor, originalBackColor;
> >>>>
> >>>> public CustomDisabledTextBox() {
> >>>> disabledBackColor = Color.LightBlue; // or whatever you like
> >>>> }
> >>>>
> >>>> protected override void OnEnabledChanged(EventArgs e) {
> >>>> if (!this.Enabled) {
> >>>> this.originalBackColor = this.BackColor;
> >>>> this.BackColor = disabledBackColor;
> >>>> } else {
> >>>> this.BackColor = originalBackColor;
> >>>> }
> >>>> base.OnEnabledChanged(e);
> >>>> }
> >>>>
> >>>> [Browsable(true)]
> >>>> public Color DisabledBackColor {
> >>>> get {
> >>>> return this.disabledBackColor;
> >>>> }
> >>>> set {
> >>>> this.disabledBackColor = value;
> >>>> }
> >>>> }
> >>>>
> >>>> }
> >>>> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> >>>>
> >>>> And use this textbox.
> >>>> When the Enable state changes in the overridden method you place the
> >>>> desired color. If the control is disabled you place yours, otherwise
> >>>> the original one.
> >>>> Also, adding the property accessor with the [Browsable(true)] attribute
> >>>> let's you define the disabled back color at design time.
> >>>>
> >>>> Done in 2 minutes so don't take this at 100% best solution ok?
> >>>> Regards
> >>>> Fabrizio
> >>>>
> >>>> <(E-Mail Removed)> wrote in message
> >>>> news:(E-Mail Removed)...
> >>>>> I'm using krypton toolkit which has allowed me to make a cool looking
> >>>>> form. However, when I set my textbox to disabled it is 'greyed' out.
> >>>>> The grey colour isn't in keeping with the office 2007 style look ofmy
> >>>>> form. How can i change the colour that control assumed when it's
> >>>>> disabled?
> >>>>>
> >>>>> Thanks!
> >>>>>
> >>>>> Gary-
> >>>>>
> >>>>
> >>>>
> >>>
> >>>
> >>
> >>

> >
> >


 
Reply With Quote
 
Fabrizio Romano
Guest
Posts: n/a
 
      8th Jan 2007
Glad if I helped a little.
Cheers
Fabrizio

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
I have just had a chance to spot the replies. Thankyou both some ideas
to get me started.
I'm going to have a play with this over the next couple of days. It's a
shame there isn't an easy way to change the colour that the control
assumes when its disabled - I would have thought this was a basic
requirement! But I guess not.

Thanks for the kind help,

Gary.

Fabrizio Romano wrote:

> You're right.
> It seems that there is not an easy solution, at least in the first 20/30
> results on google and I'm not even talking about msdn...
> Maybe he could just do the background trick I suggested setting the
> ReadOnly
> property to false instead of disabling the control.
> And if he also wants the control not to be selectable he could just handle
> the Enter() event giving the focus to some other control.
> What would you suggest?
>
> Regards,
> Fabrizio
>
>
> "Eric Moreau" <(E-Mail Removed)> wrote in message
> news:OYu%(E-Mail Removed)...
> > Your BackColor implementation is working correctly but the ForeColor
> > isn't. It has always been the problem of disabled controls.
> >
> > --
> >
> >
> > HTH
> >
> > Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
> > Conseiller Principal / Senior Consultant
> > S2i web inc. (www.s2i.com)
> > http://emoreau.s2i.com/
> >
> > "Fabrizio Romano" <(E-Mail Removed)> wrote in message
> > news:45a190a8$0$19101$(E-Mail Removed)...
> >> Well, I suppose he could just do the same for the ForeColor as what I
> >> did
> >> for the BackColor.
> >> I really had 2 minutes so I just showed the trick with one color.
> >>
> >> Regards,
> >> Fabrizio
> >>
> >> "Eric Moreau" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >>> What about the ForeColor?
> >>>
> >>> --
> >>>
> >>>
> >>> HTH
> >>>
> >>> Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
> >>> Conseiller Principal / Senior Consultant
> >>> S2i web inc. (www.s2i.com)
> >>> http://emoreau.s2i.com/
> >>>
> >>> "Fabrizio Romano" <(E-Mail Removed)> wrote in message
> >>> news:459e955e$0$19100$(E-Mail Removed)...
> >>>> My first guess would be doing something like that:
> >>>>
> >>>> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> >>>> public class CustomDisabledTextBox : System.Windows.Forms.TextBox{
> >>>>
> >>>> Color disabledBackColor, originalBackColor;
> >>>>
> >>>> public CustomDisabledTextBox() {
> >>>> disabledBackColor = Color.LightBlue; // or whatever you like
> >>>> }
> >>>>
> >>>> protected override void OnEnabledChanged(EventArgs e) {
> >>>> if (!this.Enabled) {
> >>>> this.originalBackColor = this.BackColor;
> >>>> this.BackColor = disabledBackColor;
> >>>> } else {
> >>>> this.BackColor = originalBackColor;
> >>>> }
> >>>> base.OnEnabledChanged(e);
> >>>> }
> >>>>
> >>>> [Browsable(true)]
> >>>> public Color DisabledBackColor {
> >>>> get {
> >>>> return this.disabledBackColor;
> >>>> }
> >>>> set {
> >>>> this.disabledBackColor = value;
> >>>> }
> >>>> }
> >>>>
> >>>> }
> >>>> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> >>>>
> >>>> And use this textbox.
> >>>> When the Enable state changes in the overridden method you place the
> >>>> desired color. If the control is disabled you place yours, otherwise
> >>>> the original one.
> >>>> Also, adding the property accessor with the [Browsable(true)]
> >>>> attribute
> >>>> let's you define the disabled back color at design time.
> >>>>
> >>>> Done in 2 minutes so don't take this at 100% best solution ok?
> >>>> Regards
> >>>> Fabrizio
> >>>>
> >>>> <(E-Mail Removed)> wrote in message
> >>>> news:(E-Mail Removed)...
> >>>>> I'm using krypton toolkit which has allowed me to make a cool
> >>>>> looking
> >>>>> form. However, when I set my textbox to disabled it is 'greyed' out.
> >>>>> The grey colour isn't in keeping with the office 2007 style look of
> >>>>> my
> >>>>> form. How can i change the colour that control assumed when it's
> >>>>> disabled?
> >>>>>
> >>>>> Thanks!
> >>>>>
> >>>>> Gary-
> >>>>>
> >>>>
> >>>>
> >>>
> >>>
> >>
> >>

> >
> >



 
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
How to change control state in MVC preview 3 Andy B Microsoft ASP .NET 0 14th Aug 2008 04:54 AM
change back colour when form is enabled/disabled =?Utf-8?B?c2N1YmFkaXZlcg==?= Microsoft Access Forms 0 20th Feb 2007 12:01 PM
Disabled Control Font Colour change? Bob Microsoft C# .NET 4 25th Aug 2006 06:28 AM
change colour of disabled textbox text =?Utf-8?B?QmFzaWw=?= Microsoft Excel Programming 0 25th Aug 2005 06:21 PM
Tab Control change back bround colour Ian Microsoft Access Form Coding 2 31st May 2004 08:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:42 PM.