Click here to Skip to main content
11,802,389 members (29,599 online)
Rate this: bad
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 11:59am
ThePhantomUpvoter at 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 at 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 at 26-Mar-13 18:33pm
This would be easy using WPF and ListView types of objects, cant you use something like this?
lostandconfused1234 at 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 at 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 at 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 at 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 475
1 KrunalRohit 366
2 F-ES Sitecore 295
3 Afzaal Ahmad Zeeshan 230
4 CHill60 220
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,645
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web03 | 2.8.151002.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