Solved

Mouse move event of label control (vb6)

Posted on 2003-10-24
16
979 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sameEnds challenge 3 133
why to use string 10 60
copyEvens challenge 6 92
Problem to event 3 74
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

947 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

23 Experts available now in Live!

Get 1:1 Help Now