Solved

How to highlite text using Visual Studio 2008

Posted on 2008-06-18
6
261 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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)…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

919 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now