PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Forms Button in .NET 2 - possible bug with back color

Reply

Button in .NET 2 - possible bug with back color

 
Thread Tools Rate Thread
Old 08-02-2006, 04:19 AM   #1
msw555@yahoo.com
Guest
 
Posts: n/a
Default Button in .NET 2 - possible bug with back color


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

  Reply With Quote
Old 08-02-2006, 12:55 PM   #2
Markus Hjärne
Guest
 
Posts: n/a
Default Re: Button in .NET 2 - possible bug with back color

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
>



  Reply With Quote
Old 08-02-2006, 05:03 PM   #3
msw555@yahoo.com
Guest
 
Posts: n/a
Default Re: Button in .NET 2 - possible bug with back color

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


  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off