Results 1 to 21 of 21

Thread: [RESOLVED] Label color change

  1. #1

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Resolved [RESOLVED] Label color change

    Hi all
    I am changing color of label on mouse move event
    But my question is how to get back the previous color when mouse in not on the label
    Miss I want when mouse is on the label then its color is red otherwise previous color

    See my code

    VB Code:
    1. Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. Label1.BackColor = &HFF&
    3. End Sub

    help

  2. #2
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Thumbs up Re: Label color change

    Hey it is simple. U can get the current color by this code
    VB Code:
    1. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. Label1.BackColor = 'type your previous color here
    3. End Sub
    4.  
    5. Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    6. Label1.BackColor = vbRed
    7. End Sub
    Last edited by vivek_master146; May 10th, 2006 at 05:38 AM.
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  3. #3

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Label color change

    u don't understand what i want to do

    i dont want any event on form load
    when mouse is on then label then label color is rad
    when mouse is other place of the form miss not on the label then it's color is previous color

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Label color change

    The usual solution to do this kind of stuff is to use the SetCapture API function. Unfortunatly that only works with controls that have a hWnd, which a Label doesn't. There is however another little trick you can use that involves setting the DragIcon property to a mouse pointer of your choice. This is an important step otherwise this whole thing will look very funny. I've attached a hand icon you can use if you like.

    Now for the trick, in the MouseMove event you start a Drag & Drop operation, this is because the Label will then start to fire the DragOver event, and this event will let you know when the mouse leaves the control, in which case you stop the dragging. You will actually never move the Label, you just start this operation to fire the DragOver event. The downside to this is that the MouseMove or Click events will not fire anymore. So if you use the Click event move that code into the DragDrop event instead, since that will fire when you press the mouse button.
    VB Code:
    1. Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     Label1.BackColor = vbRed
    3.     Label1.Drag vbBeginDrag
    4. End Sub
    5.  
    6. Private Sub Label1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
    7.     If State = vbLeave Then
    8.         Label1.BackColor = vbButtonFace
    9.         Label1.Drag vbEndDrag
    10.     End If
    11. End Sub
    12.  
    13. Private Sub Label1_DragDrop(Source As Control, X As Single, Y As Single)
    14.     'Use this event instead of the Click event
    15.     Debug.Print "Label1_Click"
    16. End Sub
    Just remember to set the DragIcon property (during design-time) before using this code.
    Attached Files Attached Files

  5. #5
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Label color change

    Ok I have edited my post. Hope it helps.
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Label color change

    unfortunately the Form_MouseMove method is unreliable.

    one alternative is to use a textbox and make it look like a label and then use code like this to simulate a mouse_leave event.

  7. #7
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Label color change

    Hi bushmobile there is no such mouse_leave or mouseout event in textbox.
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  8. #8

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Label color change

    hi joacim ur coding is good but label is going with the mouse

    vivek ur coding is not working well coz there r mdi form menu also toolbar also

    bush sir in ur coding label color is not changing
    please help me again

    bush and joacim help me again

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Label color change

    Quote Originally Posted by shakti5385
    hi joacim ur coding is good but label is going with the mouse
    That's because you haven't set the DragIcon property, which I mentioned twice that you'll have to set, otherwise you get that ugly outline of the label when you move the mouse over it.

  10. #10

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Label color change

    Hi joacim I went on drag icon property but window opening
    What I do???
    Help again

  11. #11
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Label color change

    Hey!!! Shakti u are not understanding what anderson is saying. U first download the
    hand.zip file and then apply the icon in ur dragicon property. The window is not opening.
    It is a common dialog.
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  12. #12
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Label color change

    Quote Originally Posted by vivek_master146
    Hi bushmobile there is no such mouse_leave or mouseout event in textbox.
    I know, you have to simulate one using setcapture as is demonstrated in the link i provided.

  13. #13
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Label color change

    Quote Originally Posted by shakti5385
    Hi joacim I went on drag icon property but window opening
    What I do???
    Help again
    In the Open dialog box that appears select an icon or cursor file of your choice. You may used one of those Hand cursors I attached in the zip file.

  14. #14

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [RESOLVED] Label color change

    thanks all

  15. #15
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: [RESOLVED] Label color change

    Thats great!!! I can use it in my project. But what about label1. It does not have any hwnd property. It is showing error.
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  16. #16
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: [RESOLVED] Label color change

    Quote Originally Posted by vivek_master146
    Thats great!!! I can use it in my project. But what about label1. It does not have any hwnd property. It is showing error.
    Is that directed at me?
    If so: that is why i said that you'd have to make a textbox look like a label.
    If not: ignore me

  17. #17
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] Label color change

    Quote Originally Posted by vivek_master146
    Thats great!!! I can use it in my project. But what about label1. It does not have any hwnd property. It is showing error.
    I mentioned this fact in my first post in this thread and that is also why I described a work-around using the Drag method.

  18. #18
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: [RESOLVED] Label color change

    No i am referring to bushmobile not anderson. Thank u bushmobile. I also want to ask that how much experienced u r in VB programming. Bloooahaha
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  19. #19
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] Label color change

    Yes, but I mentioned SetCapture in my first post. I also mentioned that a Label doesn't have a hWnd so you can't use it. So I posted another work-around, and you asked what how to use it with a Label. The answer is already available in this thread.

  20. #20
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: [RESOLVED] Label color change

    As i was going to say, JA was answering the same question. He'd already mentioned the SetCapture stuff. He suggested a work-around avoiding SetCapture, I suggested a work-around using SetCapture.

    Quote Originally Posted by vivek_master146
    I also want to ask that how much experienced u r in VB programming.
    umm, learnt a bit out of necessity when in a data entry job a couple of years back then took a break. decided to make an app for my g/f that would help her manage her teaching (she's a teacher) last year and have just learnt stuff as i go along. In the grand scheme of things probably v. little experience.

  21. #21

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [RESOLVED] Label color change

    Any one who is helping other is the best
    But I got the solution by joacim
    Thanks joacim

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