How to detect when Tab Control loses its focus

G

Guest

Hello,

I have a WinForm application. The form has one Tab Control and one
ToolStrip. I would like to know what would be the best way to detect when
the user is "leaving" the Tab Control and "moving" into ToolStrip.

Thank you
EitanB
 
G

Guest

You can handle the 'Leave' event of the TabControl to know when this object
loses focus and the 'Enter' event of the ToolStrip to know when the toolstrip
gets the focus.

Adrian.
 
G

Guest

Hello,

The leave on the Tab Control is not triggered when I press one of the
controls on the ToolStrip..... It only triggers when I switch tabs.

Thank you
Eitan

Adrian Voicu said:
You can handle the 'Leave' event of the TabControl to know when this object
loses focus and the 'Enter' event of the ToolStrip to know when the toolstrip
gets the focus.

Adrian.
--
[Please mark my answer if it was helpful to you]




Eitan said:
Hello,

I have a WinForm application. The form has one Tab Control and one
ToolStrip. I would like to know what would be the best way to detect when
the user is "leaving" the Tab Control and "moving" into ToolStrip.

Thank you
EitanB
 
P

Peter Duniho

Eitan said:
Hello,

I have a WinForm application. The form has one Tab Control and one
ToolStrip. I would like to know what would be the best way to detect when
the user is "leaving" the Tab Control and "moving" into ToolStrip.

I would expect the Enter and Leave events in the Control class to
provide that information. Is this not working for you?
 
G

Guest

Hello,

The Leave on the Tab Control is not triggered when I press one of the
controls on the ToolStrip..... It only triggers when I switch between tabs
on the Tab Control....

Thank you
Eitan
 
P

Peter Duniho

Eitan said:
Hello,

The Leave on the Tab Control is not triggered when I press one of the
controls on the ToolStrip..... It only triggers when I switch between tabs
on the Tab Control....

But do you not get an Enter event for the ToolStrip?

It seems to me that if you don't get a Leave event for the Tab Control,
the technically the Tab Control hasn't actually lost focus. So in some
respect, you are asking the wrong question. Perhaps you should look
more closely at what UI changes actually occur when what you think is
focus changing happens.

All that said, there's always the WndProc. You can override the WndProc
for the Tab Control and see what messages are sent when the UI changes
in the way you want to detect (for example, use Debug.WriteLine() to
trace the message values). Then you can either take advantage of that
information to find a managed way to handle the change, or just keep the
WndProc overridden and watch for those same messages.

Pete
 
G

Guest

The TabControl is loosing the focus you are right.

Using the WndProc might be a good idea. How would one trap the WndProc
messages?

Thank you,
Eitan
 
G

Guest

I read the article with the example for a form. How ever, how would I
overide the WndProc for a control (TabPage) on the form?

In my case, the form is defined as:
public partial class WeldProgramSetup : Form

My TabControl is defined as:
private System.Windows.Forms.TabControl tabControl_WP_ChannelInfo;

and my TabPage is defined as:
private System.Windows.Forms.TabPage tabPage_WP_Flow;

Thank you,
Eitan
 
P

Peter Duniho

Eitan said:
I read the article with the example for a form. How ever, how would I
overide the WndProc for a control (TabPage) on the form?

The same way you do it for a form: you create a new class that inherits
the class you want to override, and use that class in place of the
original one.

Pete
 

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