让班点击事件C# [英] giving classes click events C#

查看:98
本文介绍了让班点击事件C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我只是想知道如果那里有一种方式让班有自己的点击事件。例如我有一个卡类,并且是有了解的方式,当在长方形的用户点击(显示卡的图像)从类

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?

推荐答案

要获得在这里点击鼠标从Windows消息,你需要有一个窗口句柄;在的WinForms,从任何派生Windows.Forms.Control将有一个窗口句柄,它会得到鼠标消息。这些信息会被自动翻译成.NET的MouseDown,的MouseUp,鼠标点击等事件的调用。

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.

这篇关于让班点击事件C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆