Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > text box


Reply
 
Thread Tools Display Modes
  #1  
Old 02-21-2006, 07:55 AM
PAguilar07's Avatar
PAguilar07 PAguilar07 is offline
Centurion
 
Join Date: Nov 2005
Location: Texas
Posts: 187
Default text box


How do you automatically highlight text that is being passed into a text box at form load? That way the user can just hit delete or backspace and he doesn't have to hightlight the text with the mouse?
Reply With Quote
  #2  
Old 02-21-2006, 07:58 AM
morbidangel morbidangel is offline
Regular
 
Join Date: Apr 2005
Posts: 91
Default

Try this in your Form_load event (assuming Text1 is your textbox)
Code:
Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) Text1.SetFocus
Reply With Quote
  #3  
Old 02-21-2006, 08:05 AM
George7a's Avatar
George7a George7a is offline
Saved by Grace
 
Join Date: Mar 2005
Location: Nazareth
Posts: 1,697
Default

Here are two ways:

Code:
Private Sub Form_Load() Text2.TabIndex = 0 ' here you tell it that this is the first control to have focus Text2.SelStart = 0 Text2.SelLength = Len(Text2.Text) End Sub
Or to use set foucs in Form Activate..
Code:
'Form Activate Private Sub Form_Activate() Text2.SetFocus End Sub ' Form Load Private Sub Form_Load() Text2.SelStart = 0 Text2.SelLength = Len(Text2.Text) End Sub
I hope it helps,

- George
Reply With Quote
  #4  
Old 02-21-2006, 08:12 AM
PAguilar07's Avatar
PAguilar07 PAguilar07 is offline
Centurion
 
Join Date: Nov 2005
Location: Texas
Posts: 187
Default

Thanks morbidangel, and George7A
Reply With Quote
  #5  
Old 02-21-2006, 08:23 AM
PAguilar07's Avatar
PAguilar07 PAguilar07 is offline
Centurion
 
Join Date: Nov 2005
Location: Texas
Posts: 187
Default

Ok, i used the txtpassword.tabindex = 0
txtpassword.selstart = 0
txtpassword.selLength = len(txtPassword.text)
but it still doesn't hightlight all the text in the text box.

what am i do wrong?
Reply With Quote
  #6  
Old 02-21-2006, 08:25 AM
George7a's Avatar
George7a George7a is offline
Saved by Grace
 
Join Date: Mar 2005
Location: Nazareth
Posts: 1,697
Default

You might have other textboxes that has tabindex = 0

Try the set focus if you don't want to change the tab order
Reply With Quote
  #7  
Old 02-21-2006, 08:39 AM
PAguilar07's Avatar
PAguilar07 PAguilar07 is offline
Centurion
 
Join Date: Nov 2005
Location: Texas
Posts: 187
Default

ok I tried your other code and it still won't hightlight the text?
Reply With Quote
  #8  
Old 02-21-2006, 09:13 AM
George7a's Avatar
George7a George7a is offline
Saved by Grace
 
Join Date: Mar 2005
Location: Nazareth
Posts: 1,697
Default

You need debug it line by line to figure out why! maybe other objects are taking the focus or it is not set properly.

I attached a sample code.

If you share your code you will get more help

- George
Attached Files
File Type: zip simple.zip (1.3 KB, 4 views)
Reply With Quote
  #9  
Old 02-21-2006, 11:38 AM
PAguilar07's Avatar
PAguilar07 PAguilar07 is offline
Centurion
 
Join Date: Nov 2005
Location: Texas
Posts: 187
Default

Sorry, im am very sorry I was just very stupid. I was trying to hightlight the text even before it was being populated.
Reply With Quote
  #10  
Old 02-21-2006, 12:14 PM
George7a's Avatar
George7a George7a is offline
Saved by Grace
 
Join Date: Mar 2005
Location: Nazareth
Posts: 1,697
Default

Thats OK

It is good that you post that so I would not go so far with my imagination

Good Luck

- George
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->