我正在为可视化工具编写拖动系统.单击并拖动时,它会移动您在窗口中看到的内容.当鼠标击中面板边缘时,我开始重新定位光标,使其永远不会离开框.它跟踪光标在盒子内部的虚拟位置.这部分代码工作正常.
只要有一个MouseMoved事件并且位置在框内,我就会执行Cursor.Show().如果它在框外,我会做Cursor.Hide().当用户放开鼠标按钮时,我执行Cursor.Show().
有很多问题.当第一次Hide调用发生时,它不会隐藏.我必须将光标的虚拟位置移到包含窗口之外才能发生隐藏.当我搬回来时,即使正在调用Show,它也不会变得可见.最后,当释放鼠标按钮时,尽管显示被调用,但光标不会出现.
而不是要求人们调试我的代码,我只是想知道事件系统中发生了什么使得Cursor.Hide/Show不能按照我期望的方式工作.我的印象是,如果一个名为Hide的控件,光标会在该控件内部被隐藏; 同样如果我从控件中调出show.
Mr.*_*elp 12
对于有这个问题的人,尝试这样的事情:
private bool _CursorShown = true;
public bool CursorShown
{
get
{
return _CursorShown;
}
set
{
if (value == _CursorShown)
{
return;
}
if (value)
{
System.Windows.Forms.Cursor.Show();
}
else
{
System.Windows.Forms.Cursor.Hide();
}
_CursorShown = value;
}
}
Run Code Online (Sandbox Code Playgroud)
并使用它:
CursorShown = false; // Will hide the cursor
CursorShown = false; // Will be ignored
CursorShown = true; // Will show the cursor
CursorShown = true; // Will be ignored
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5224 次 |
| 最近记录: |