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

Change the colour of the disabled state of a control?

P: n/a
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-

Jan 5 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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

<ga********@myway.comwrote in message
news:11**********************@s80g2000cwa.googlegr oups.com...
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-

Jan 5 '07 #2

P: n/a
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" <fa******@tin.itwrote in message
news:45***********************@reader4.news.tin.it ...
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

<ga********@myway.comwrote in message
news:11**********************@s80g2000cwa.googlegr oups.com...
>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-


Jan 7 '07 #3

P: n/a
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" <er*********************@videotron.cawrote in message
news:uG**************@TK2MSFTNGP03.phx.gbl...
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" <fa******@tin.itwrote in message
news:45***********************@reader4.news.tin.it ...
>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

<ga********@myway.comwrote in message
news:11**********************@s80g2000cwa.googleg roups.com...
>>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-



Jan 8 '07 #4

P: n/a
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" <fa******@tin.itwrote in message
news:45***********************@reader4.news.tin.it ...
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" <er*********************@videotron.cawrote in message
news:uG**************@TK2MSFTNGP03.phx.gbl...
>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" <fa******@tin.itwrote in message
news:45***********************@reader4.news.tin.i t...
>>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

<ga********@myway.comwrote in message
news:11**********************@s80g2000cwa.google groups.com...
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-



Jan 8 '07 #5

P: n/a
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" <er*********************@videotron.cawrote in message
news:OY***************@TK2MSFTNGP04.phx.gbl...
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" <fa******@tin.itwrote in message
news:45***********************@reader4.news.tin.it ...
>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" <er*********************@videotron.cawrote in message
news:uG**************@TK2MSFTNGP03.phx.gbl...
>>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" <fa******@tin.itwrote in message
news:45***********************@reader4.news.tin. it...
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

<ga********@myway.comwrote in message
news:11**********************@s80g2000cwa.googl egroups.com...
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-
>




Jan 8 '07 #6

P: n/a
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" <er*********************@videotron.cawrote in message
news:OY***************@TK2MSFTNGP04.phx.gbl...
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" <fa******@tin.itwrote in message
news:45***********************@reader4.news.tin.it ...
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" <er*********************@videotron.cawrote in message
news:uG**************@TK2MSFTNGP03.phx.gbl...
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" <fa******@tin.itwrote in message
news:45***********************@reader4.news.tin.i t...
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

<ga********@myway.comwrote in message
news:11**********************@s80g2000cwa.google groups.com...
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-


Jan 8 '07 #7

P: n/a
Glad if I helped a little.
Cheers
Fabrizio

<ga********@myway.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...
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" <er*********************@videotron.cawrote in message
news:OY***************@TK2MSFTNGP04.phx.gbl...
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" <fa******@tin.itwrote in message
news:45***********************@reader4.news.tin.it ...
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" <er*********************@videotron.cawrote in message
news:uG**************@TK2MSFTNGP03.phx.gbl...
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" <fa******@tin.itwrote in message
news:45***********************@reader4.news.tin.i t...
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

<ga********@myway.comwrote in message
news:11**********************@s80g2000cwa.google groups.com...
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-



Jan 8 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.