Click here to Skip to main content
13,094,732 members (96,997 online)
Rate this:
Please Sign up or sign in to vote.
See more: (untagged)
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 26-Mar-13 11:59am
ThePhantomUpvoter 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.
ThePhantomUpvoter 26-Mar-13 18:47pm
There is no "command". You have to cast sender to Label and then change the visibility. Try something like ((Label)sender)->Visibility = Visible;

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Cast the "sender" argument into a Control and that will give you the possiblity of using all the methods and properties of a control.
Control ctrl = (Control) sender;
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 26 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100