Solved

Make a textbox act loke the ones on the the internet

Posted on 2014-09-10
5
97 Views
Last Modified: 2014-09-11
txtLname.enabled = false this makes the text a lighter color.
but doing this does not allow MouseMove, gotfocus, click or any events
I want to check the contents eg;
if txtLname.text = "Last Name" then
txtLname.enabled = true
End if
but when it's disabled it does not respond to any events.
How to do this ?
0
Comment
Question by:isnoend2001
[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
5 Comments
 
LVL 17

Assisted Solution

by:vb_elmar
vb_elmar earned 200 total points
ID: 40316366
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Static Allowed As Byte
    With txtLname
        Allowed = 1
        If X < .Left Then Allowed = 0
        If X > (.Left + .Width) Then Allowed = 0
        If Y < .Top Then Allowed = 0
        If Y > (.Top + .Height) Then Allowed = 0
        If Allowed = 1 Then 'if the mouse cursor is above textbox, Allowed is = 1
            If .Text = "Last Name" Then .Enabled = True
        End If
    End With
End Sub

Open in new window

0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 40316374
here is another sample :
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    mySub txtLname, X, Y
End Sub

Private Sub mySub(ByVal L As TextBox, ByVal X As Long, ByVal Y As Long)
    Static Allowed As Byte
    With L
        Allowed = 1
        If X < .Left Then Allowed = 0
        If X > (.Left + .Width) Then Allowed = 0
        If Y < .Top Then Allowed = 0
        If Y > (.Top + .Height) Then Allowed = 0
        If Allowed = 1 Then 'if the mouse cursor is over the disabled textbox, Allowed is = 1
            If .Text = "Last Name" Then .Enabled = True
        End If
    End With
End Sub

Open in new window

0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 300 total points
ID: 40316390
Try setting the Locked property to false instead of the Enabled property, If you want it to look disabled, change the Forecolor to the Disabled Text colour (&H80000011&)
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40317160
If one of the above answers helps then please ignore this question, but what is it exactly that you are trying to do? Do you want to be able to detect (for example) mousemove over the textbox but not allow the user to change the text. You can do that with this code:

Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub

Open in new window

0
 

Author Closing Comment

by:isnoend2001
ID: 40317167
Thanks people no need to disable or lock just changing the text color works fine
Private Sub Form_Load()
 If txtLname.Text = "Last Name" Then      
        txtLname.ForeColor = (&H80000011)
     End If

Private Sub txtLname_GotFocus()
  If txtLname.Text = "Last Name" Then
    txtLname.ForeColor = vbDefault
    txtLname.Text = vbNullString
  End If
End Sub
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

752 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