943,729 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 2444
  • C# RSS
Sep 29th, 2009
0

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

Expand Post »
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:

C# Syntax (Toggle Plain Text)
  1. private void Maintenance_Load(object sender, EventArgs e)
  2. {
  3. tabControl1.Focus();
  4. tabControl1.SelectedIndex = 0;
  5. txt_CLName.Focus();
  6. }
Similar Threads
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
phoenix_dwarf is offline Offline
57 posts
since May 2009
Sep 29th, 2009
0

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

Hi,

I ran the same code and it focuses fine.
You dont need to call
C# Syntax (Toggle Plain Text)
  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.
Reputation Points: 512
Solved Threads: 246
Nearly a Posting Virtuoso
Ryshad is offline Offline
1,260 posts
since Aug 2009
Sep 29th, 2009
1

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

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:

Quote 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:
c# Syntax (Toggle Plain Text)
  1. tabControl1.SelectedIndex = 0;
  2. txt_CLName.Select();
Reputation Points: 293
Solved Threads: 82
Posting Whiz
Antenka is offline Offline
361 posts
since Nov 2008
Sep 29th, 2009
0

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

Tnx Antenka...it works. I'm just puzzled by why my original code doesn't want to work...? l0olâ„¢ Ahw well, thnx again!
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
phoenix_dwarf is offline Offline
57 posts
since May 2009
Sep 29th, 2009
0

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

You're welcome
Reputation Points: 293
Solved Threads: 82
Posting Whiz
Antenka is offline Offline
361 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Different character colours in a label (or any other control)?
Next Thread in C# Forum Timeline: is an Enum the right way to go?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC