giving classes click events C#

后端 未结 3 1918
不知归路
不知归路 2021-01-14 12:50

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 r

3条回答
  •  忘掉有多难
    2021-01-14 13:18

    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.

提交回复
热议问题