仅在控件中锁定鼠标光标移动
我有一个图片框,我使用位图在其上绘制一些内容(每次更改绘图后将位图加载为图片框图像)。现在我有一个“添加注释”按钮。这个按钮位于主窗体中的某个位置。我希望这样,当用户单击此按钮时,鼠标指针会跳转到图片框控件中,并且不会移出它,除非用户在控件内部单击或按 Escape 键。这可能吗?
我目前正在使用此代码:
private void buttonAddNote_Click(object sender, EventArgs e)
{
Cursor = Cursors.Cross;
}
或者更好的方法可能是在用户单击“添加注释”按钮时,鼠标单击仅在图片框组件内起作用(IE 用户无法单击程序中的其他位置)
I have a picture box which I draw some stuff on it using a bitmap (loading the bitmap as picturebox image after each change of drawing). Now I have a "Add a note" button. this button is somewhere in the mainForm. I want it so when user clicks on this button, the mouse pointer to jump into picturebox control and does not move out of it unless the user has clicked inside the control or pressed Escape key. Is this possible?
I am using this code at the moment:
private void buttonAddNote_Click(object sender, EventArgs e)
{
Cursor = Cursors.Cross;
}
Or a better approach could be on this time when user clicked add a note button, mouse clicks only work within picturebox component (IE user can not click somewhere else in program)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第二,虽然你对用户限制的看法是正确的,所以我想出了这个想法。但非常感谢您向我展示如何锁定用户鼠标!十)
On the second though you are right about user limitations, so I came up with this idea. But thanks a lot for showing me how to lock user mouses!!! X)
用户界面中的这种模式是一个非常糟糕的主意。但 Winforms 确实使之成为可能。您可以使用 Cursor.Clip 属性来限制运动。它不能阻止用户仍然使用键盘快捷键访问“开始”菜单,您需要使用 Capture 属性来检测您是否丢失。
Modality like that in a user interface is a pretty bad idea. But Winforms does make it possible. You can use the Cursor.Clip property to restrict motion. It can't prevent the user from still accessing, say, the Start menu with a keyboard shortcut, you need to use Capture property to detect that you lost.