本文介绍了应该有一些一般的鼠标事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好, 我遇到了鼠标事件的问题。任何相关的帮助都是apreciated。 我有一个表格,其中有2个按钮。和im 使用mousemove事件处理程序在运行时移动(拖动)这些按钮 但我在两个按钮的两侧有相同的代码。 所以我想知道有没有办法找出哪个控件被选中 on mousedown然后只调用一个通用函数2按钮 将处理拖延。 谢谢 sagar 解决方案 sagar写道: 所以我想知道有没有办法找出哪个控件被选中 on mousedown然后调用只有一个2按钮的通用功能, 将处理拖动。 是的,鼠标事件处理程序中的sender参数是引发事件的对象 。您可以使用它来确定点击了哪个按钮 。 Chris Dunaway写道: sagar写道: 所以我想知道有没有办法找出哪个控件是选择 $ m $ b on mousedown然后只调用一个通用函数2按钮 将处理draging。 是的,鼠标事件处理程序中的sender参数是引发事件的对象 。您可以使用它来确定单击了哪个按钮 。 感谢您的回复。 但问题是,即时使用OnMouseDown()事件,这是在 $ b时引发的当我点击button1然后button1_mousedown(..)是 筹集时,$ bi点击表单。没有一般的mousedown功能,无论是在窗体上还是在控件上,每个mousedown都需要 ,从那里我可以找到 在我点击的地方。 sagar写道: Chris Dunaway写道: sagar写道: 所以我想知道有没有办法找出哪个控件被选中 on mousedown and然后只为2个按钮调用一个通用函数, 将处理draging。 是的,鼠标事件处理程序中的sender参数是引发事件的对象 。您可以使用它来确定单击了哪个按钮 。 感谢您的回复。 但问题是,我使用OnMouseDown()事件,这是在 $ b时引发的当我点击button1然后button1_mousedown(..)是 筹集时,$ bi点击表单。没有一般的mousedown功能,无论是在窗体上还是在控件上,每个mousedown都需要 ,从那里我可以找到 在我点击的地方。 换句话说,你使用鼠标在 表单上选择一个控件,比如按钮,然后你就可以了想要通过 将其拖动到窗体上的其他位置来移动该控件。所以你需要知道如何确定点击了哪个控件。 我不知道我知道如何帮助你。您可以获得鼠标单击的x,y 坐标,然后循环浏览 您的表单上的控件,并查明该点是否占用了占用的区域通过 你的控制。 也许其他人可以建议更好的方法。 抱歉 hi everyone, i m having a problem with mouse events. any help related is apreciated. i m having a form in which i m having 2 buttons. and i mmoving(draging) these buttons on run time using mousemove event handlerbut i m having same code in side two mousedown for two buttons. so i want to know is there a way to find out which control is selectedon mousedown and then call only one generic function for 2 button whichwill handle draging. thankssagar 解决方案 sagar wrote: so i want to know is there a way to find out which control is selectedon mousedown and then call only one generic function for 2 button whichwill handle draging.Yes, the sender parameter in your mouse event handler is the objectthat raised the event. You can use that to determine which button wasclicked. Chris Dunaway wrote: sagar wrote: so i want to know is there a way to find out which control is selected on mousedown and then call only one generic function for 2 button which will handle draging. Yes, the sender parameter in your mouse event handler is the objectthat raised the event. You can use that to determine which button wasclicked.thanks for the reply.but the problem is, i m using OnMouseDown() event which is raised wheni clicks on form when i clicks on button1 then button1_mousedown(..) israised. no general mousedown function is there which is called forevery mousedown either on form or on controls and from there i can findout where i have clicked. sagar wrote:Chris Dunaway wrote: sagar wrote: so i want to know is there a way to find out which control is selected on mousedown and then call only one generic function for 2 button which will handle draging. Yes, the sender parameter in your mouse event handler is the object that raised the event. You can use that to determine which button was clicked. thanks for the reply.but the problem is, i m using OnMouseDown() event which is raised wheni clicks on form when i clicks on button1 then button1_mousedown(..) israised. no general mousedown function is there which is called forevery mousedown either on form or on controls and from there i can findout where i have clicked.So in other words, you are using the mouse to select a control on theform, such as a button, and you then want to move that control bydragging it somewhere else on the form. So you need to know how todetermine which control has been clicked. I''m not sure I know how to help you. You could possibly get the x,ycoordinates of the mouse click and then loop through the controls onyour form and find out if that point is withing the area taken up byyour control. Perhaps someone else will be able to suggest a better approach. Sorry 这篇关于应该有一些一般的鼠标事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-12 16:05