Solved

Make a textbox act loke the ones on the the internet

Posted on 2014-09-10
5
93 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
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 46

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

786 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