Results 1 to 5 of 5

Thread: HighLight Label with move move over label

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    North East America
    Posts
    463

    Post

    I have a program that when a mouse moves over a label it changes color. I can do the first color change fine but when the mouse moves off the label I want it to change back to the original color. If anyone knows how to do this I would appreciate the help. I did find some code that does this with VB6 but its to large and confusing plus its for the Web and not for an exe program.

    Please help

    Troy

    ------------------
    Troy MacPherson
    Customer Suport Software Analyst
    [email protected]



  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Sure thing:

    Code:
    Private Sub Form_Load()
        m_lColor = Label1.BackColor
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Label1.BackColor = m_lColor
    End Sub
    
    
    Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Label1.BackColor = vbRed
    End Sub

    Regards,

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819


  3. #3
    Junior Member
    Join Date
    Nov 1999
    Posts
    21

    Post

    Dim temp As Double
    Private Sub Form_Load()
    temp = Label1.BackColor
    End Sub

    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Label1.BackColor = temp
    End Sub

    Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Label1.BackColor = 10 'some color
    End Sub

    try this out!!!!!!

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    North East America
    Posts
    463

    Post

    Thanks guys but I had already tried these things and I guess the problem is that I have 4 labels on the for and I can get label 1 to work but the other three just wont light up? I got some code from another BBS and its good code but when I use it I can't click the label of my choice and get the results i need. Here is the code that I got maybe one of you guys can figure out whats wrong? Pay attention to the SetCapture when I rem that out it works better.
    'Module
    Public Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
    Public Declare Function ReleaseCapture Lib "user32" () As Long

    'code
    Private Sub LblNewGame_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    'Put this in the mouse_move event of your control:

    With LblNewGame
    If Button = 0 Then
    If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then
    ReleaseCapture
    'Do your 'mouse-exit' stuff here
    .ForeColor = &HFFFF00 '&H808000
    ' Else
    SetCapture (hwnd)
    ' Do your 'mouse-enter' stuff here
    .ForeColor = &HFFFF00
    End If
    End If
    End With
    End Sub

    Any ideas?

    Thanks


    ------------------
    Troy MacPherson
    Customer Suport Software Analyst
    [email protected]



  5. #5
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    If you're going to be using alot of these "Hover" Labels then you'd be better off making a Control or using a Class, e.g.

    In a Class Module, Named: HoverLabel..
    Code:
    Public WithEvents Label As Label
    
    Private Sub Label_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If TypeName(oLastLabel) = "Nothing" Then
            Set oLastLabel = Label
            Label.ForeColor = vbBlue
            Label.FontUnderline = True
        End If
    End Sub
    In a Module..
    Code:
    Public oLastLabel As Label
    In a Form with 3 Labels..
    Code:
    Private Link1 As New HoverLabel
    Private Link2 As New HoverLabel
    Private Link3 As New HoverLabel
    
    Private Sub Form_Load()
        Set Link1.Label = Label1
        Set Link2.Label = Label2
        Set Link3.Label = Label3
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If TypeName(oLastLabel) = "Nothing" Then Exit Sub
        oLastLabel.ForeColor = vbWindowText
        oLastLabel.FontUnderline = False
        Set oLastLabel = Nothing
    End Sub
    
    Private Sub Label1_Click()
        'Play Code to Jump to URL in Label1 Here..
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

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