PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
Button in .NET 2 - possible bug with back color
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
Button in .NET 2 - possible bug with back color
![]() |
Button in .NET 2 - possible bug with back color |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
I'm encountering strange behavior when modifying the back color of a
button. Actually when I try to restore the button's original back color I have the problem. The button does not get back its original back color. Try the following: 1. Create a new windows forms application. 2. Place a button on the form. 3. In the event handler for the button click write the following code: this.button1.BackColor = this.button1.BackColor; 4. Run the application and press the button. 5. The color of the button changes, although according to the code you wrote it should clearly remain the same. At least that's the behavior I'm getting. Does anyone have an idea why this happens and / or how to work around it? Thanks |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Hi,
I could reproduce your problem and I think I can explain what is happening. When you add a button to the form, the property UseVisualStyleBackColor is true by default. When you change the BackColor property in your handler, the UseVisualStyleBackColor is automatically changed to false. (It also changes when you set the BackColor in the designer). If you add the line this.button1.UseVisualStyleBackColor = true; after the line this.button1.BackColor = this.button1.BackColor;, the background color won't change. Hope this help. /Markus <msw555@yahoo.com> skrev i meddelandet news:1139372365.899322.41530@g47g2000cwa.googlegroups.com... > I'm encountering strange behavior when modifying the back color of a > button. > Actually when I try to restore the button's original back color I have > the problem. The button does not get back its original back color. > Try the following: > 1. Create a new windows forms application. > 2. Place a button on the form. > 3. In the event handler for the button click write the following code: > this.button1.BackColor = this.button1.BackColor; > 4. Run the application and press the button. > 5. The color of the button changes, although according to the code you > wrote it should clearly remain the same. At least that's the behavior > I'm getting. > > Does anyone have an idea why this happens and / or how to work around > it? > > Thanks > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Thanks!
Markus Hjärne wrote: > Hi, > > I could reproduce your problem and I think I can explain what is happening. > > When you add a button to the form, the property UseVisualStyleBackColor is > true by default. > When you change the BackColor property in your handler, the > UseVisualStyleBackColor is automatically changed to false. > (It also changes when you set the BackColor in the designer). > If you add the line this.button1.UseVisualStyleBackColor = true; after the > line this.button1.BackColor = this.button1.BackColor;, > the background color won't change. > > Hope this help. > > /Markus > > <msw555@yahoo.com> skrev i meddelandet > news:1139372365.899322.41530@g47g2000cwa.googlegroups.com... > > I'm encountering strange behavior when modifying the back color of a > > button. > > Actually when I try to restore the button's original back color I have > > the problem. The button does not get back its original back color. > > Try the following: > > 1. Create a new windows forms application. > > 2. Place a button on the form. > > 3. In the event handler for the button click write the following code: > > this.button1.BackColor = this.button1.BackColor; > > 4. Run the application and press the button. > > 5. The color of the button changes, although according to the code you > > wrote it should clearly remain the same. At least that's the behavior > > I'm getting. > > > > Does anyone have an idea why this happens and / or how to work around > > it? > > > > Thanks > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

