Solved

For text box...

Posted on 2002-04-15
6
133 Views
Last Modified: 2010-05-02
Suppose I have a textbox control, say Text1. Whenever I focus on the textbox the text will automatically selected(ie. in windows it will be hilighted in blue) and whenever I write on it it deletes the previous content.
Please write some code.

regards
Subhasis
0
Comment
Question by:mitra_subhasis
6 Comments
 
LVL 50

Accepted Solution

by:
Ryan Chong earned 10 total points
ID: 6941443
Hi,

Use SendKeys "{Home}+{End}", example:

Private Sub Text1_Click()
    SendKeys "{Home}+{End}"
End Sub

Private Sub Text1_GotFocus()
    SendKeys "{Home}+{End}"
End Sub
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6941445
Private Sub Text1_GotFocus()
 With Text1
  .SelStart = 0
  .SelLength = Len(.Text)
 End With
End Sub
0
 

Expert Comment

by:sweetpillow
ID: 6941527
Hi mitra,

  Try the following code. Suppose I have a text box in the form1 name text1.

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Text1.BackColor = vbWhite
End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    Text1.Text = ""
End Sub

Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Text1.BackColor = vbBlue
    Text1.SetFocus
End Sub

Cheers,
Sweetpillow :)
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:mitra_subhasis
ID: 6941534
That's very pretty...

Thanking you,'
Subhasis
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6941536
sweetpillow, it would indeed work, however you would need to reset the colours in the KeyDown event otherwise it will still stay white on blue.

Anyway the snippet I posted achieves everything required with less code. ryancys's suggestion would also work but sendkeys is not necessarily the most reliable method.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6941538
Ah well mitra_subhasis, you chose a solution which is your right, I would stand by my last comment that sendkeys is not necessarily the MOST reliable way to achieve this when you can do it more simply with the suggestion I gave!
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Basic Excel Formatting error 4 106
Run code from text file in vb 1 64
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 47
VB6 - Scroll Mouse wheel on Picturebox 13 44
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

773 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