Solved

How to highlite text using Visual Studio 2008

Posted on 2008-06-18
6
269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 
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

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

726 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