Solved

Mouse move event of label control (vb6)

Posted on 2003-10-24
16
981 Views
Last Modified: 2008-02-07
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
  • 5
  • 4
  • 2
  • +2
16 Comments
 
LVL 1

Expert Comment

by:paulott
ID: 9616280
You're going to have to change all the labels in every _mouseover event, setting the current one (the label that the mouse is over) to the color you want, and the rest to the original. In these examples, I'm using vbgray as the "original" color.

         private sub lblExam1_mousemove(.......)
              lblexam1.forecolor=vbgreen
              lblexam2.forecolor=vbgray
              lblexam3.forecolor=vbgray
         end sub
         private sub lblExam2_mousemove(.......)
              lblexam2.forecolor=vbgreen
              lblexam1.forecolor=vbgray
              lblexam3.forecolor=vbgray
         end sub
         private sub lblExam3_mousemove(.......)
              lblexam3.forecolor=vbgreen
              lblexam1.forecolor=vbgray
              lblexam2.forecolor=vbgray
         end sub

You probably want to add the defaults to your Form_MouseMove() too. This will deselect any label you just had your mouse over:

         private sub Form_mousemove(.......)
              lblexam1.forecolor=vbgray
              lblexam2.forecolor=vbgray
              lblexam3.forecolor=vbgray
         end sub

Hope that helps.
0
 
LVL 3

Expert Comment

by:pg_india
ID: 9618848
I suggest you to do like this:

private sub Label1_mousemove(.......)
    If X < 20 Or X > Label1.Width - 20 Or Y < 20 Or Y > Label1.Height - 20 Then
    Label1.ForeColor = vbGreen
Else
    Label1.ForeColor = vbWhite
End If

end sub

try this..................
0
 
LVL 8

Expert Comment

by:harris_c
ID: 9630888
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 3

Expert Comment

by:pg_india
ID: 9631492
i saw this code...but why u use api when it can easily be done...

anyway it is upto ALIHAIDER1 to decide....
0
 

Author Comment

by:ALIHAIDER1
ID: 9631687
Dear expert pg_india
        Ur code is not perfect working. The color of the control is not changed event the mouse move from the control to another. The color remain vbgreen. Pls provide some perfection to aviod using api. will wait for ur response.
Thanks
Ali
0
 

Author Comment

by:ALIHAIDER1
ID: 9657242
Dear expert
pls respond upon my qeury. Kindly do needful because i here is  something remains penging here.
Ali
0
 
LVL 1

Expert Comment

by:paulott
ID: 9658853
Hello Ali.

Did my try my example up above?

Thanks,
- Paul
0
 
LVL 3

Expert Comment

by:pg_india
ID: 9662049
The color of the control is not changed event the mouse move from the control to another????

The color chages whenever the mouse moves out of a control....i don't thk there is any problem with that...
0
 

Author Comment

by:ALIHAIDER1
ID: 9662772
Ok will try again.
Ali
0
 

Author Comment

by:ALIHAIDER1
ID: 9662790
Dear expert Paul
           Your code is working good. But that 's not what i want. Actuly i want to manage this from one subroutine (mouse move).
Thanks for concern
Ali
0
 
LVL 8

Accepted Solution

by:
harris_c earned 50 total points
ID: 9675413
You have a special requirement, and simple programming won't do it.  Why not just use APIs?  

Anyways, check the code below on subclassing - but will will still require a code in the form load.

'Put this code in your form
Private clsLblBox1 As Class1
Private clsLblBox2 As Class1

Private Sub Form_Load()
    Set clsLblBox1 = New Class1
    Set clsLblBox1.LabelBoxCtl = Label1
    Set clsLblBox2 = New Class1
    Set clsLblBox2.LabelBoxCtl = Label2
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Label1.ForeColor = vbgray
    Label2.ForeColor = vbgray
End Sub



'put this code in a class module named Class1
Private WithEvents lbl As Label

Public Property Set LabelBoxCtl(lblBox As Label)
    Set lbl = lblBox
End Property

'this subroutine controls *all* specified label mousemoves
Private Sub lbl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
   lbl.ForeColor = vbGreen
End Sub




This is the most I can give you - using API and subclassing.



hec",)
0
 
LVL 3

Assisted Solution

by:pg_india
pg_india earned 50 total points
ID: 9676308
Why don't u try making a ocx for a label and on mouse move of the label you can call the API or my code,whichever u feel is working fine...



0
 

Author Comment

by:ALIHAIDER1
ID: 9677921
That's realy good idea and i will adopt the same.
I will respond early.
Ali
0
 
LVL 3

Expert Comment

by:ashoooo
ID: 9883407
Ali, check my response to the other question that you have posted.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

838 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