Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing textbox.forecolor OnMouseover

Status
Not open for further replies.

mybers

IS-IT--Management
Mar 24, 2004
62
PH
Hi Again....

This site has been a great help for me studying my projects.

It seems my subject has been posted already sometime but anyway I hope anyone can point to me in the reight direction.

Question: I have a set of text box which forms like a navigation menu. I would like to do is OnmouseOver the text.forecolor will change.

Also, if possible to add a sound file OnMouseOver too

Thanks in advance

 
Hello Mybers

You didn't specify the type of sound file you want to play, but here is a link to play .wav & .midi files.

I found this using the advanced search for "playing wav files". Copy it into a new module. Move the 'sub' to Play Sound to just above the PlayMidiFile Sub... Remove Option Explicit, or Redim the variables as 'Strings'.
Hope this helps


Now for the Mouse-Over...
I use this for labels, but it will work on a textbox also.
I commented out the code I use with the labels, In case you want to switch to labels instead. Give's a nice appearance. On MouseOver it looks like a button!

For each 'control' you want to change add this to the On Mouse Move Properties
Code:
=LabelMouseMove("Label0")

Besure to change the 'controls' name each time

If you use labels add this to the On Mouse Down Properties
Code:
=LabelMouseDown("Label0")

Paste this code into your form

Code:
'Private Function LabelMouseDown(strLabelName As String)
'On Error Resume Next
'    With Me.Controls(strLabelName)
'        .SpecialEffect = 2  'Sunken
'    End With
'End Function

Private Function LabelMouseMove(strLabelName As String)
On Error Resume Next
    With Me.Controls(strLabelName)
'        .SpecialEffect = 1  'Raised
        .ForeColor = 16711680   'Light Blue
'If your playing different sounds
'Insert a Select Case Statement Here
         Call PlaySound("C:\yourfile.wav")
    End With
End Function

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next

    Me.Label0.SpecialEffect = 0 'Flat
    Me.Label0.ForeColor = 0 'Black
    Me.Label1.SpecialEffect = 0
    Me.Label1.ForeColor = 0
'Tek-Tips Test
    Me.txtBox1.ForeColor = 0
    Me.txtBox2.ForeColor = 0
    
End Sub

As I mentioned I use this for labels, but I'm sure if you want to play around with the textbox formats you could achieve a nice appearance also.

Hope this help...





AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
Hi Mybers,

I did a little testing...
You need to add a variable otherwise the file will play twice.

I declared a global one on the form.
Code:
Option Compare Database
Option Explicit
Dim intSoundCounter As Integer

Modified Code
Code:
Private Function LabelMouseMove(strLabelName As String)
On Error Resume Next
    With Me.Controls(strLabelName)
      '  .SpecialEffect = 1  'Raised
        .ForeColor = 16711680   'Light Blue
    End With
    
        If intSoundCounter = 0 Then
            Select Case strLabelName
                Case "About"
                    Call PlaySound("C:\about.wav")
                    intSoundCounter = 1
                Case "Help"
                    Call PlaySound("C:\help.wav")
                    intSoundCounter = 1
                Case Else
            End Select
        End If
End Function

Modified Code

Code:
Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next

    Me.Label0.SpecialEffect = 0 'Flat
    Me.Label0.ForeColor = 0 'Black
    Me.Label1.SpecialEffect = 0
    Me.Label1.ForeColor = 0
    Me.txtBox1.ForeColor = 0
    Me.txtBox2.ForeColor = 0
    intSoundCounter = 0
End Sub

Enjoy...


AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
Hi AccessGurucarl

The sound script seems to be complicated for now, Anyway I would like to focus on the OnMouseDown/Move for the meantime.

I have set of labels now forming like a navigation menu. What I want to achieve is that when the Mouse gets over the Label will change and back on MOuseMove and move to next labels like having a loop or something..

I hope I have described this clearly...
Below are the lablels I used. ofcourse each of them when click will open a subform.

me.applicants
me.Benefits
me.contacts
me.dependents
me.educational
me.employeemovement
me.licensed
me.moredetails
me.personal_details
me.prevemployer
me.report

Any modification pls?...

Thanks


 
Not sure I'm understanding you?
I think this is what your asking for.

If you place your mouse over any label -
The caption will change color...
When you move off the label -
The caption returns back to the default color.


If this is correct, then Paste this code into the forms VBE window. Add the rest of your labels in the Detail_MouseMove Sub just like the 3 I added.

Code:
Private Function LabelMouseDown(strLabelName As String)
On Error Resume Next
    With Me.Controls(strLabelName)
        .SpecialEffect = 2  'Sunken
    End With
End Function

Private Function LabelMouseMove(strLabelName As String)
On Error Resume Next
    With Me.Controls(strLabelName)
        .SpecialEffect = 1  'Raised
        .ForeColor = 16711680   'Light Blue
    End With
End Function

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next

me.applicants.SpecialEffect = 0 'Flat
me.applicants.ForeColor = 0 'Black
me.Benefits.SpecialEffect = 0 'Flat
me.Benefits.ForeColor = 0 'Black
me.contacts.SpecialEffect = 0 'Flat
me.contacts.ForeColor = 0 'Black
...
... For every label you want to change
...
...  
End Sub

Now open the form in design view.
Right click a label,choose properties
Locate the Label Name; we'll use lblApplicants for the 1st one as an example.

Next, Locate the On Mouse Move and On Mouse Down Event

Type or paste these into the correct events...
=LabelMouseMove("lblApplicants")

=LabelMouseDown("lblApplicants")

Make sure you include the equal sign!

Repeat this for each label on the form, replacing "lblApplicants" with the correct label name.

That's it...
The sound really isn't that hard to add-in, I would change it to the MouseDown Event, if you put it into use. Keep in mind, play quick sound files, nothing to long.

Let me know what you think about the label effect, once you get it in place. I think you'll like it!

AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top