473,503 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change the colour of the disabled state of a control?

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
7 11743
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3177
by: Craig | last post by:
I have a page that has a few columns and totals. I've been asked to amke sure that not only is the totals boxes readonly, they must not accept focus from the cursor. However, setting the bo to...
6
5217
by: Louise | last post by:
Hi I have written an HTML pages which does not have any colour specifying tags as far I know. When I view this in an Microsoft internet explorer browser it appears with a white background and...
2
6590
by: Scott | last post by:
Is it possible to have a button change colour OnClick ? Thanks.
4
5652
by: | last post by:
Please, help. I created my contol, ButtonX, which subclasses System.Forms.Windows.Button class. I am doing my own paiting, by overriding OnPaint and OnPaintBackground (without calling base...
6
4468
by: Mantorok | last post by:
Hi all Is it possible to disable a Control in .Net but have the text colour always in black? I would rather use Enabled property rather than Readonly as it does everything I need it to in one...
2
7103
by: Kubuli John | last post by:
I have a LinkButton in an ASP.NET web form. Depending on the current state of affairs, I either enable or disable the link button in by code-behind class (e.g., disable the "Previous" button if...
4
2410
by: Mel | last post by:
how can i change disabled background on all form elements ?
4
8578
by: Bob | last post by:
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...
3
2394
by: helraizer1 | last post by:
Hi all, On one page of my site I have a form (code below) with an input textbox with the id "message". You type in your message in this field (as the id suggests) and depending on an option in a...
0
7063
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7258
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
7313
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
7441
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3146
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1489
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
366
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.