Change the colour of the disabled state of a control?

G

garyusenet

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-
 
F

Fabrizio Romano

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

Eric Moreau

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 said:
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 said:
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 said:
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

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-
 
F

Fabrizio Romano

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 said:
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 said:
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 said:
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/

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

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-
 
G

garyusenet

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 said:
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 said:
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 said:
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

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/

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

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-
 
F

Fabrizio Romano

Glad if I helped a little.
Cheers
Fabrizio

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 said:
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 said:
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 said:
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

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/

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

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-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top