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

  • Thread starter Thread starter Larry Woods
  • Start date Start date
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
 
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.
 
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.
 
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.
 
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
 
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
 
Back
Top