Click here to Skip to main content
11,920,156 members (58,331 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++/CLI
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 12:59pm
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
0 OriginalGriff 455
1 phil.o 170
2 CPallini 150
4 F-ES Sitecore 130
0 OriginalGriff 6,778
1 KrunalRohit 4,495
2 Sergey Alexandrovich Kryukov 3,153
3 George Jonsson 2,810
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web03 | 2.8.151120.1 | Last Updated 26 Mar 2013
Copyright © CodeProject, 1999-2015
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