Solved

Make a textbox act loke the ones on the the internet

Posted on 2014-09-10
5
88 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 45

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now