Solved

How to highlite text using Visual Studio 2008

Posted on 2008-06-18
6
258 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

707 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

15 Experts available now in Live!

Get 1:1 Help Now