Click here to Skip to main content
13,354,886 members (69,915 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have a C# program.
when you push a button,I want it to load another windows form that has different tabs.I want it to start from different tabs,when I push different buttons.
for example:
I push the: 'student' button,I expect it to open the windows form with student tab selected.
and when I push the: 'teacher' button, I expect it to open the same windows form with teacher tab selected.

I use this code to open windows form:

Form frm = new Form2();
frm.ShowDialog() // or even Show(). but neither worked :(

I have used select(),and focus() methods.but they didn't work :(
and also I used this approach:

ActiveControl = frm.Controls["tbTabs"].Controls["studentTab"];

but it didn't work either :(
Posted 25-Jan-13 12:03pm
Updated 25-Jan-13 12:04pm
jibesh 25-Jan-13 19:37pm
was this answered here ?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You need to use myForm.Activate():[^].

Some background: focus means nothing but "keyboard focus". There is only one focused window in the whole system at a time. Activation is something different: it is applied only to top-level windows (like forms; they are all top-level by default), shows active window title, etc., but it also effects dispatching of input events to an application.

When a window has a control with keyboard focus, and then deactivated, this control always loose focus. When you activate a form again, the control which had focus last time will get it again.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.180111.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100