How do you focus on text box in tab control on form load?

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2009
Posts: 40
Reputation: phoenix_dwarf is an unknown quantity at this point 
Solved Threads: 0
phoenix_dwarf phoenix_dwarf is offline Offline
Light Poster

How do you focus on text box in tab control on form load?

 
0
  #1
Sep 29th, 2009
Hi, i'm trying to focus the cursor on a textbox inside one of my tab controls (3 tabs) but my method doesn't seem to work...Any ideas?
Here is my code:

  1. private void Maintenance_Load(object sender, EventArgs e)
  2. {
  3. tabControl1.Focus();
  4. tabControl1.SelectedIndex = 0;
  5. txt_CLName.Focus();
  6. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 379
Reputation: Ryshad has a spectacular aura about Ryshad has a spectacular aura about 
Solved Threads: 68
Ryshad's Avatar
Ryshad Ryshad is offline Offline
Posting Whiz

Re: How do you focus on text box in tab control on form load?

 
0
  #2
Sep 29th, 2009
Hi,

I ran the same code and it focuses fine.
You dont need to call
  1. tabControl1.Focus();
since you then move focus to the textbox.
When you set the SelectedIndex for the tabControl are you selecting the tab page which contains the textbox?

The other thing to do is check that nothing is calling focus away from the textbox after you set focus to it.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 254
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training

Re: How do you focus on text box in tab control on form load?

 
1
  #3
Sep 29th, 2009
Hello, phoenix_dwarf.

While playing with your code found interesting thingy: it works fine on every tab .. except the 1st one. Anyway, while trying to explain such behaviour, found this:

Originally Posted by MSDN
Note:
Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.
So, this should work fine:
  1. tabControl1.SelectedIndex = 0;
  2. txt_CLName.Select();
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 40
Reputation: phoenix_dwarf is an unknown quantity at this point 
Solved Threads: 0
phoenix_dwarf phoenix_dwarf is offline Offline
Light Poster

Re: How do you focus on text box in tab control on form load?

 
0
  #4
Sep 29th, 2009
Tnx Antenka...it works. I'm just puzzled by why my original code doesn't want to work...? l0olâ„¢ Ahw well, thnx again!
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 254
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training

Re: How do you focus on text box in tab control on form load?

 
0
  #5
Sep 29th, 2009
You're welcome
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC