Solved

How to highlite text using Visual Studio 2008

Posted on 2008-06-18
6
268 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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