954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

set focus on textbox during start up

I actually want to ask two things,
first, how do I set Textbox1 to get focus so that the user will not have to click the textbox if he wants to write something, the .focus() method does not work

also, how do I highlight texts inside a textbox programmatically. I think the equivalent code for this in VB 6.0 is Home+End. I hope you got I mean

markdean.expres
Junior Poster
152 posts since Aug 2010
Reputation Points: 10
Solved Threads: 1
 

If you have a text field named txtMytext and it contains "abcdefghijklmnop" then the following code

txtMytext.Focus()
txtMytext.SelectionStart = 3
txtMytext.SelectionLength = 6

will set focus to the control with "defghi" selected.

Reverend Jim
Posting Shark
Moderator
1,169 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
 

This will work only if you are trying to highlight everything in the textbox.

TextBox1.Focus()
TextBox1.SelectAll()
bluehangook629
Posting Whiz in Training
204 posts since Dec 2009
Reputation Points: 11
Solved Threads: 14
 

To do the focus and highligh all the text inside ot it:

texrBox1.Focus()
texrBox1.SelectionStart = 0
texrBox1.SelectionLength = textBox1.Text.Lenght
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
 

Guys, you've been very helpful to me, thanks. I love you!!! this thread has been solved!

markdean.expres
Junior Poster
152 posts since Aug 2010
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You