Solved

Mouse move event of label control (vb6)

Posted on 2003-10-24
16
978 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Upgraded from php 5.2.7 to 5.3 getting errors to my website 18 53
tripleUp challenge 7 67
MaxSpan challenge 9 67
seriesUp challenge 7 107
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

759 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