Connect with Expertise | Find Experts, Get Answers, Share Insights

How can I catch tab change on a TabControl?

David Rose
 
Posts: n/a
#1: Nov 15 '05
I would like to catch the tab change before it occurs. There is a
SelectedIndexChanged event to catch the change after it occurs. How do I
catch when the user clicks on a tab, but before the TabPage changes?

Is there anything like the TCN_SELCHANGING notification?

TIA

David Rose




David Rose
 
Posts: n/a
#2: Nov 15 '05

re: How can I catch tab change on a TabControl?


Nicholas,

Thanks. That works fine.

I was hoping that there would be an easier way, but I guess that for some
reason that event is not handled in .NET.

David


"Nicholas Paldino [.NET/C# MVP]" <nicholas.paldino@exisconsulting.com> wrote
in message news:OK1y7Z8cDHA.2640@TK2MSFTNGP09.phx.gbl...[color=blue]
> David,
>
> You should be able to hook into the windows procedure of the parent of
> the tab control and catch that notification. You just have to override[/color]
the[color=blue]
> WndProc method on that container.
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - nicholas.paldino@exisconsulting.com
>
> "David Rose" <david@silverswitch.net> wrote in message
> news:%23RMNIRzcDHA.2368@TK2MSFTNGP09.phx.gbl...[color=green]
> > I would like to catch the tab change before it occurs. There is a
> > SelectedIndexChanged event to catch the change after it occurs. How do[/color][/color]
I[color=blue][color=green]
> > catch when the user clicks on a tab, but before the TabPage changes?
> >
> > Is there anything like the TCN_SELCHANGING notification?
> >
> > TIA
> >
> > David Rose
> >
> >
> >[/color]
>
>[/color]


Mike Shane
 
Posts: n/a
#3: Nov 15 '05

re: How can I catch tab change on a TabControl?


You could use the MouseDown event to determine that the user has clicked on
the tab contol and then check to see what tab was clicked.

Mike Shane
MST Associates



"David Rose" <david@silverswitch.net> wrote in message
news:uJ6xb9AdDHA.2436@TK2MSFTNGP09.phx.gbl...[color=blue]
> Nicholas,
>
> Thanks. That works fine.
>
> I was hoping that there would be an easier way, but I guess that for some
> reason that event is not handled in .NET.
>
> David
>
>
> "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldino@exisconsulting.com>[/color]
wrote[color=blue]
> in message news:OK1y7Z8cDHA.2640@TK2MSFTNGP09.phx.gbl...[color=green]
> > David,
> >
> > You should be able to hook into the windows procedure of the parent[/color][/color]
of[color=blue][color=green]
> > the tab control and catch that notification. You just have to override[/color]
> the[color=green]
> > WndProc method on that container.
> >
> > Hope this helps.
> >
> >
> > --
> > - Nicholas Paldino [.NET/C# MVP]
> > - nicholas.paldino@exisconsulting.com
> >
> > "David Rose" <david@silverswitch.net> wrote in message
> > news:%23RMNIRzcDHA.2368@TK2MSFTNGP09.phx.gbl...[color=darkred]
> > > I would like to catch the tab change before it occurs. There is a
> > > SelectedIndexChanged event to catch the change after it occurs. How[/color][/color][/color]
do[color=blue]
> I[color=green][color=darkred]
> > > catch when the user clicks on a tab, but before the TabPage changes?
> > >
> > > Is there anything like the TCN_SELCHANGING notification?
> > >
> > > TIA
> > >
> > > David Rose
> > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


David Rose
 
Posts: n/a
#4: Nov 15 '05

re: How can I catch tab change on a TabControl?


Mike,

That was the first thing I tried. For some reason that event fires after
the SelectedIndexChanged event for the TabControl. I am not sure how
Windows Forms routes events. Know a good source of information on Forms
event routing?

Handling the WM_NOTIFY message works as expected.

David


"Mike Shane" <mike.shane@msta.com> wrote in message
news:OmdaMubdDHA.2168@TK2MSFTNGP09.phx.gbl...[color=blue]
> You could use the MouseDown event to determine that the user has clicked[/color]
on[color=blue]
> the tab contol and then check to see what tab was clicked.
>
> Mike Shane
> MST Associates
>
>
>
> "David Rose" <david@silverswitch.net> wrote in message
> news:uJ6xb9AdDHA.2436@TK2MSFTNGP09.phx.gbl...[color=green]
> > Nicholas,
> >
> > Thanks. That works fine.
> >
> > I was hoping that there would be an easier way, but I guess that for[/color][/color]
some[color=blue][color=green]
> > reason that event is not handled in .NET.
> >
> > David
> >
> >
> > "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldino@exisconsulting.com>[/color]
> wrote[color=green]
> > in message news:OK1y7Z8cDHA.2640@TK2MSFTNGP09.phx.gbl...[color=darkred]
> > > David,
> > >
> > > You should be able to hook into the windows procedure of the[/color][/color][/color]
parent[color=blue]
> of[color=green][color=darkred]
> > > the tab control and catch that notification. You just have to[/color][/color][/color]
override[color=blue][color=green]
> > the[color=darkred]
> > > WndProc method on that container.
> > >
> > > Hope this helps.
> > >
> > >
> > > --
> > > - Nicholas Paldino [.NET/C# MVP]
> > > - nicholas.paldino@exisconsulting.com
> > >
> > > "David Rose" <david@silverswitch.net> wrote in message
> > > news:%23RMNIRzcDHA.2368@TK2MSFTNGP09.phx.gbl...
> > > > I would like to catch the tab change before it occurs. There is a
> > > > SelectedIndexChanged event to catch the change after it occurs. How[/color][/color]
> do[color=green]
> > I[color=darkred]
> > > > catch when the user clicks on a tab, but before the TabPage changes?
> > > >
> > > > Is there anything like the TCN_SELCHANGING notification?
> > > >
> > > > TIA
> > > >
> > > > David Rose
> > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Closed Thread