Solved

How to highlite text using Visual Studio 2008

Posted on 2008-06-18
6
267 Views
Last Modified: 2013-11-26
Hi!

Have this app in Visual Studio 2008. VB.NET

And want to highlight a textbox, when the object got focus.

Insert this line into Gotfocus event....

        Text1.SelectionStart = 0
        Text1.Select(0, Text1.Text.Length)

But it dosen work ???

Please help ASAP.

0
Comment
Question by:team2005
  • 4
  • 2
6 Comments
 
LVL 19

Expert Comment

by:Stephen Manderson
ID: 21811750
This should work

        If TextBox1.SelectionLength = 0 Then
            TextBox1.SelectionStart = 0
            TextBox1.SelectionLength = TextBox1.TextLength
            TextBox1.Select()
        End If

Regards
Steve
0
 
LVL 2

Author Comment

by:team2005
ID: 21811786
Hi!

No, dosent work ???
0
 
LVL 19

Expert Comment

by:Stephen Manderson
ID: 21811804
Sorry, was testing the selction from a button event and not got foucs. Problem seems to be that when you click the box the mouse event is triggered and the selection in the gotfocus is removed.

You could simple put

Textbox1.SelectAll() in the MouseUp event for the text box
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 19

Accepted Solution

by:
Stephen Manderson earned 500 total points
ID: 21811832
The following will select all the text in the textbox.

    'Selects all the text in the textbox when got focus, can be used for tab navigation
    Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus
        TextBox1.SelectAll()
    End Sub

    'When a mouse press occurs on the textbox select all the text
    Private Sub TextBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseUp
        TextBox1.SelectAll()
    End Sub

    'Sets the focus to the textbox1 on form load
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TextBox1.Select()
    End Sub
0
 
LVL 2

Author Closing Comment

by:team2005
ID: 31468294
Very good, workink now. Thanks
0
 
LVL 19

Expert Comment

by:Stephen Manderson
ID: 21811936
Your most welcome

Glad I could help!

Regards
Steve
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Powershell File Sort 8 41
Formula for calculating ROI on training 6 49
Upgrading my SSIS package in VS 2012 6 60
System.net.Sockets Error 5 26
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question