Solved

Mouse move event of label control (vb6)

Posted on 2003-10-24
7
653 Views
Last Modified: 2010-07-27
I manage a label control mouse move event to change the forecolor of the control when the mouse move over the control. But there is a problem that on mouse move event this subroutine changes the forecolor but when the mouse move from the label control to another it does not changes the forecolor which was before the mouse move event was triggered.
pls help me for the same.
sub like this
     private sub lblExam_mousemove(.......)
              lblexam.forecolor=vbgreen
         end sub
and how can i change the forecolor of the control through this sub .
pls help me
0
Comment
Question by:ALIHAIDER1
7 Comments
 
LVL 2

Expert Comment

by:BUCHAS
Comment Utility
alright, suppose the default forecolor of your label is vbred and you want to change it to vbgreen every time the user pass the mouse over it:

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    lblexam.ForeColor = vbRed

End Sub

Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
   
    lblexam.ForeColor = vbGreen
   
End Sub
0
 

Author Comment

by:ALIHAIDER1
Comment Utility
Dear expert
        Actuly that's not what i want. I want to manage the same within the label control subroutine. It may be handel through x and y coordinates. Or may be u have any other solution.
I dont want to use the form_mouseover sub.
I want to use just label1_mousemove sub.
Pls help me and thanks for respose.
Ali
0
 
LVL 1

Accepted Solution

by:
polital earned 50 total points
Comment Utility
This should be simple.

Create a global variable
        Private ctrl as control

In the Form load
       set ctrl = nothing

In the mousemove routine

     if not (ctrl  is nothing) then
         ctrl.Forecolor = vbButtonFace  '  or whatever your default color is
     end if

    lbl.ForeColor = vbGreen
    set ctrl = lbl

This should do it.

polital


0
 
LVL 1

Expert Comment

by:polital
Comment Utility
I forgot to add in the interests of efficiency at the beginning of the mousemove routine

if ctrl is lbl then exit sub

You don't want to keep setting the color - once will do.

polital
0
 
LVL 3

Assisted Solution

by:ashoooo
ashoooo earned 50 total points
Comment Utility
You want to change the color of the label back to its original color as soon as the mouse if moved out. Am I right?

If yes, there is no simple way to do this other than write some code in the mouseover event handlers of other controls. Even writing code in mouseover eventhandler for the form is NOT enough; because if the mouse is moved over another control and doesnt get over the form, the form will never get a mouseover event and the color of your control will never change.

Try capturing the mouse on mouseover. This will send mouseover event to your control even when it leaves the boundry. Then check if the mouse has left the boundry. If yes, change the color of your control to normal and release the mouse.

Hope this helps.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now