Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 102
  • Last Modified:

Make a textbox act loke the ones on the the internet

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
isnoend2001
Asked:
isnoend2001
2 Solutions
 
vb_elmarCommented:
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
 
vb_elmarCommented:
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
 
GrahamSkanCommented:
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
 
Martin LissRetired ProgrammerCommented:
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
 
isnoend2001Author Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now