Application.EnableVisualStyles() breaks my program!

  • Thread starter Michael A. Covington
  • Start date
M

Michael A. Covington

I added Application.EnableVisualStyles() as the first statement in Main() of
my program, and didn't notice much change in visual appearance, but what I
*did* notice is that some of my buttons stopped working! They were enabled
but no longer called their OnClick methods.

I tried adding Application.DoEvents() right after EnableVisualStyles and
that didn't help.

What gives? In VS 2005/.NET 2.0, is EnableVisualStyles broken? This is
under Windows XP.
 
M

Marc Gravell

Works fine from everything I have seen... Does it fix itself if you
remove this line again?

I suspect that what has happened is that at some point you have gone
into the form designer, and it has decided to drop your events from the
init step; this always happens if you cut / paste a control around on
the form, but the designer is also notorious for doing freaky things at
the most inoportune times.

Just check the current (form) class against an old (working) version -
see what changed; I suspect a missing "this.{control}.{event} += {blah
handler};".

And if you think events are brittle in the designer, don't go *near*
data-binding in the designer ;-p

Marc
 
T

Tom Spink

Michael said:
I added Application.EnableVisualStyles() as the first statement in Main()
of my program, and didn't notice much change in visual appearance, but
what I
*did* notice is that some of my buttons stopped working! They were
enabled but no longer called their OnClick methods.

I tried adding Application.DoEvents() right after EnableVisualStyles and
that didn't help.

What gives? In VS 2005/.NET 2.0, is EnableVisualStyles broken? This is
under Windows XP.

Hi Michael,

Without more information, I'm unable to reproduce your bug. However, a
couple of things to look for is the FlatStyle property of your buttons. It
needs to be set to System in order for them to render in the System's
visual style. Are you using the Windows Forms Designer? Do the visual
styles show up there while you are designing your form?

Thanks,
-- Tom Spink
 
M

Michael A. Covington

Tom Spink said:
Hi Michael,

Without more information, I'm unable to reproduce your bug. However, a
couple of things to look for is the FlatStyle property of your buttons.
It
needs to be set to System in order for them to render in the System's
visual style. Are you using the Windows Forms Designer? Do the visual
styles show up there while you are designing your form?

Thanks,
-- Tom Spink

Thanks for responding. I'm going to check out the FlatStyle property, and
in fact any other property that might distinguish the afflicted buttons from
other ones. Also, the way I create my initial form is rather complicated
(several forms pop up at once when the program starts) and I'm going to
experiment with cutting out all the complexity (even if I lose part of the
program) to see if I can get the problem to go away.

What is really bizarre is that one of the buttons works OK until I put data
into a DataGridView that is on the same form, and then it stops working
properly.
 

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