(More info) EnableVisualStyles breaks my program!

  • Thread starter Michael A. Covington
  • Start date
M

Michael A. Covington

Further to previous post...

I have a big, complex program which works fine as long as I don't call
EnableVisualStyles.

If I do this:

Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new FormOpeningMenu());

then in one of my subordinate forms, which consits of buttons on other
things on a tab control, the non-focused buttons cease to work. Only the
focused on will actually call its OnClick procedure, although all of them
look, visually, as if they are being pressed.

My other forms are unafflicted.

On the afflicted form, the focus is being set programmatically by things
like button1.Select() or button1.Focus() (it doesn't matter which I use).

Does this ring any bells for anyone?

Many thanks!
 
M

Michael A. Covington

See bottom...
I have a big, complex program which works fine as long as I don't call
EnableVisualStyles.

If I do this:

Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new FormOpeningMenu());

then in one of my subordinate forms, which consits of buttons on other
things on a tab control, the non-focused buttons cease to work. Only the
focused on will actually call its OnClick procedure, although all of them
look, visually, as if they are being pressed.

Also, you cannot change the focus by hitting Tab.
My other forms are unafflicted.

On the afflicted form, the focus is being set programmatically by things
like button1.Select() or button1.Focus() (it doesn't matter which I use).

In fact, if I do not set focus programmatically (with the Select() or
Focus() method) the problem goes away.

Yet I cannot reproduce the problem in a separate, simpler program. That
makes me wonder if there is something pathological about the form on which
it is happening.

Any ideas?
 
M

Michael A. Covington

Solved!

I was handling the Paint event of a form and setting focus to certain
buttons when it was painted.

With visual styles turned on, the Paint event arises a lot more often, and
in particular, it arises when the user is starting to press a button. (The
button border changes color.)

So I was stealing the focus away from the button that the user was pressing.

No longer doing that... and it works fine.
 

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