Results 1 to 8 of 8

Thread: Need Code

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Location
    Central US
    Posts
    183

    Need Code

    I have been looking without success to find info on making a label show different text upon a mouse hovering over the label.
    I know this can be done with very little effort but I just can’t find any info on that.
    What I would like to do is, have a Label called E-Mail Me that changes to my email address when the mouse hovers over it then on click opens mail client.
    Thanks!

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    For the first part..put a label on a form, and then copy this code to your form...

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    4.     Label1.Caption = "[email protected]"
    5. End Sub

  3. #3
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    Place Label (Label1) on the form, copy and paste this code

    VB Code:
    1. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    2.  
    3. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    4.     HoverLabel Label1, "E-mail Me", False, vbBlack
    5. End Sub
    6.  
    7. Private Sub Label1_Click()
    8.     ShellExecute Me.hwnd, "Open", "mailto:[email protected]", 0, 0, 3
    9. End Sub
    10.  
    11. Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    12.     HoverLabel Label1, "[email protected]", True, vbBlue
    13. End Sub
    14.  
    15. Private Sub HoverLabel(LBL As Label, strText As String, FontUnderline As Boolean, FontColor As ColorConstants)
    16.     With LBL
    17.         .Caption = strText
    18.         .Font.Underline = FontUnderline
    19.         .ForeColor = FontColor
    20.     End With
    21. End Sub

  4. #4
    Lively Member
    Join Date
    Apr 2001
    Posts
    64

    Here's the rest

    That guys code will change the button when you move your mouse on top of it. If you want the button to revert back to its original state, add some code to the form's mouse_move event to change the caption back. You could set booleans on each to make sure you're not constantly changing captions on controls.

  5. #5
    Lively Member
    Join Date
    Apr 2001
    Posts
    64
    Man andreys... you beat me to it...

  6. #6
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    but it will not work very well, ie if you move your mouse really fast the form will not register the mouse move on the form, or if you move over other controls it wont reset.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  7. #7
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    That is true...any other ideas???

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Location
    Central US
    Posts
    183
    Andreys!
    OK that works great, however, would someone please take the time to explain I don’t want to use it if I don’t understand it.
    Just a short explanation would be much appreciated.
    Thanks a lot!!!!!!!!!!!!!!!!!!!!!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width