Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

giving classes click events C#

Tags:

c#

class

events

Hi i was just wondering if theres a way to give classes there own click event. For instance i have a card class, and is there a way of knowing when the user clicks on the rectangle (that displays the picture of the card) from that class?

or better yet, how do i go about knowing when the cards rectangle is clicked?

like image 411
Bigfatty Avatar asked Dec 22 '22 19:12

Bigfatty


1 Answers

To get "mouse was clicked here" messages from Windows, you need to have a window handle; in WinForms, anything deriving from Windows.Forms.Control will have a window handle, and it will get mouse messages. Those messages will be translated automatically into invocations of the .NET MouseDown, MouseUp, MouseClick etc. events.

So probably your card should be a control. If it's not (e.g. if you have a "Hand" control that is responsible for managing and drawing lots of cards) then that control needs to be the one that gets mouse events (e.g. MouseClick) and figures out which card actually got clicked based on the context and the coordinates of the mouse event.

like image 101
mqp Avatar answered Dec 28 '22 06:12

mqp