Solved

For text box...

Posted on 2002-04-15
6
135 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
[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
6 Comments
 
LVL 51

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

740 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