Click here to Skip to main content
11,712,126 members (77,600 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# windows.forms
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 Frown | :(
and also I used this approach:

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

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

1 solution

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

Solution 1

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
  Permalink  

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

  Print Answers RSS
0 CHill60 335
1 Sergey Alexandrovich Kryukov 254
2 OriginalGriff 230
3 Andy Lanng 160
4 Maciej Los 130
0 CHill60 335
1 Sergey Alexandrovich Kryukov 245
2 OriginalGriff 230
3 Andy Lanng 160
4 Maciej Los 130


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2015
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