Solved

Make a textbox act loke the ones on the the internet

Posted on 2014-09-10
5
98 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 48

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month7 days, 1 hour left to enroll

622 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