Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
3.00/5 (1 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:

C#
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:

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


but it didn't work either :(
Posted
Updated 25-Jan-13 11:04am
v2
Comments
Jibesh 25-Jan-13 19:37pm    
was this answered here ?
http://www.codeproject.com/Questions/534515/SelectingplustabsplusinplusaplusTabplusControlplus

1 solution

You need to use myForm.Activate(): http://msdn.microsoft.com/en-us/library/system.windows.forms.form.activate.aspx[^].

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.

—SA
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900