How do I select text in textbox (highlighted) like I used to do in VB 6?

L

Larry Woods

Hi,

Can't figure out how to highlight text in a textbox for reentry of input.
Used to do it with SelectLength and SelectStart but this doesn't seem to
work with .NET.

Ideas?

TIA,

Larry Woods
 
H

Herfried K. Wagner [MVP]

Hello,

Larry Woods said:
Can't figure out how to highlight text in a textbox for
reentry of input. Used to do it with SelectLength and
SelectStart but this doesn't seem to work with .NET.

There are 2 ways: You can call the textbox's 'Select' method to select the
part of text you want to select or set the textbox's 'SelectionStart' and
'SelectionLength' properties.
 
R

Rob Windsor

Larry,

You use the Select method of the TextBox, it takes two parameters start and
length. You could also use the SelectAll method wich selects all the text.
 
S

Steven Bras [MS]

The code is a little different:

TextBox1.SelectionStart = 0
TextBox1.SelectionLength = TextBox1.Text.Length

Hope this helps!

Steven Bras, MCSD
Microsoft Developer Support/Data Access Technologies

This posting is provided "AS IS" with no warranties, and confers no rights.

Microsoft Security Announcement: Have you installed the patch for Microsoft
Security Bulletin MS03-026?  If not Microsoft strongly advises you to
review the information at the following link regarding Microsoft Security
Bulletin MS03-026
http://www.microsoft.com/security/security_bulletins/ms03-026.asp and/or to
visit Windows Update at http://windowsupdate.microsoft.com to install the
patch. Running the SCAN program from the Windows Update site will help to
insure you are current with all security patches, not just MS03-026.
 
L

Larry Woods

Nope! Sorry, guy, but "None of the Above!"

When I select the text I want it "blued out" so that the next keystroke
overrides what was there. I will be using this is the Enter event handler.
I tried all of the suggestions and none of them highlight the text.

What am I missing?

TIA,

Larry Woods
 
C

Cor

Larry,
Did you know that the Enter event is not a keyboard event but has the
oposite meaning from leave control.
"Enter, gotfocus, leave, validating, validated, lostfocus"
Maybe you did want to use this, but I doubt it,
I think you want a button or something or a keyevent like keydown.
Just some guesses
Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top