如何在C#中鼠标单击同一位置时添加标签?
我的程序有一个图片框,我希望通过单击鼠标或选择 ContextMenuStrip,使某些内容出现在单击的同一位置。
如图所示,我想在特定的点击日期区域添加某种注释(可能添加用户控件)
我该怎么做?我如何发送点击坐标(x,y)并使某些内容出现在这些相同的坐标处?
谢谢 !
my program has a picturebox, and I want, apon a mouse click, or on ContextMenuStrip choice, to make something appear at the same spot of the click.
as seen in the picture, i would like to add some kind of a note on the specific clicked date area (probably add a user control)
How do i go at it ? how can i send the click cordinates (x,y) and make something appear at these same coordinates ?
Thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将创建一个类,该类将提供菜单项并捕获 x,y 坐标,以便在单击该项目时准备好它们。或者您可以在匿名委托中捕获这些坐标。
像这样的东西:
I would create a class which would provide menu items and capture x,y coordinates to have them ready when the item is clicked. Or you can capture these coordinates in an anonymous delegate.
Something like this:
满足您要求的示例代码,在下面的代码中,我添加了鼠标单击时的按钮控件。您可以根据需要修改代码。
An sample code for your requirement, In my below code i am adding button control on mouse click. You can modify the code as per ur need.
您可以使用工具提示或使用 mousemove 事件。此事件将为您提供鼠标当前的 xy 位置,然后您可以通过该位置可见的 true/false 显示您的内容,或者获取标签并设置其文本,然后根据鼠标的 xy 设置其 xy 位置。然后在 mouseleave 事件中将该标签移至屏幕外或隐藏
you can use either tool tip or use mousemove event. this event will provide you current xy postion of mouse and then you can show your content by either visible true/false at that place or take a label and set its text and then set its xy position according to xy of mouse. and then on mouseleave event move that label to off screen or hide