Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In windows forms, I have an array of labels. These are in different positions throughout the program. Furthermore, there is not a specified amount - they are created during run time, with the amount depending on what the user clicks.

I have a mouse hover event, which they all link to. However, I dont know how to find out which label the mouse is hovering over. Can you somehow access which control is sending the event?

I tried sender-> but nothing comes up I can see a use for...

Many thanks.
Posted
Comments
[no name] 26-Mar-13 18:08pm    
sender would be the label that is raising the event. What does "nothing comes up I can see a use for" mean?
lostandconfused1234 26-Mar-13 18:27pm    
what's the command to determine the label? I want to be able to use it to change the visibility
Kenneth Haugland 26-Mar-13 18:33pm    
This would be easy using WPF and ListView types of objects, cant you use something like this?
lostandconfused1234 26-Mar-13 18:40pm    
Well I have no idea what WPF is and lists are a weak point so not really ^_^ I'm sure there's a way of using the ready made event but i duno how to do it.

(System::Object^ sender, System::EventArgs^ e)

sender ->

options: Equals, Finalise, GetHashCode, GetType, MemberwiseClone, ReferenceEquals, ToString.

I duno how these could be utilised for my purpose though. I just want to change the visibility of that label
Kenneth Haugland 26-Mar-13 18:42pm    
Something on the line of IF e.LEftButton.Pressed = True then ..
Then find the element that is clicked should not be that difficult even if you woul dhave to calculate the position of the click.

1 solution

Cast the "sender" argument into a Control and that will give you the possiblity of using all the methods and properties of a control.
C#
Control ctrl = (Control) sender;
 
Share this answer
 
Comments
lostandconfused1234 26-Mar-13 18:53pm    
Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900