Label Click Event Location
-
Hello all. Take a Label with Image or ImageList and add Click Event. Then.... ...Determine if click event occurred within the bounds of the image or within the bounds of the label text. Any Ideas? (I know I could just make two controls, an image and a label and put them next to each other....but humour me a little please:))
-
Hello all. Take a Label with Image or ImageList and add Click Event. Then.... ...Determine if click event occurred within the bounds of the image or within the bounds of the label text. Any Ideas? (I know I could just make two controls, an image and a label and put them next to each other....but humour me a little please:))
You can get the screen coordinates of the mouse using the static
Control.MousePosition
property. Translate that to client coordinates using the instance methodPointToClient
on the control - presumably theLabel
or whatever you need - to get the control-relative coordinates:void myLabel_Click(object sender, EventArgs E)
{
Point p = myLabel.PointToClient(MousePosition);
// ...
}This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]