Ric*_*ral 5 c# mouse position cursor winforms
我有一个带有简单气球提示的Windows Forms应用程序。根据应用程序在桌面上的窗口位置和鼠标光标的位置,气球“提示”(或气球指向箭头)可能会或可能不会指向我想要的位置。
例如,我的应用程序贴靠在桌面侧,当它贴靠在右侧时,如果鼠标光标在右侧的100px以下,则气球“提示”将指向错误的位置。但是,如果鼠标光标位于其他任何地方,它将指向正确的位置。
在这种情况下,我想将鼠标光标位置伪造(实际上不更改鼠标光标位置)到其他位置,这样就不会发生此问题。
这可能吗?我该如何实现?
private void noteTitleInput_KeyPress(object sender, KeyPressEventArgs e) {
if(e.KeyChar == Convert.ToChar(Keys.Return, CultureInfo.InvariantCulture) && noteTitleInput.Text.Length > 0) {
e.Handled = true;
noteInputButton_Click(null, null);
} else if(!Char.IsControl(e.KeyChar)) {
if(Array.IndexOf(Path.GetInvalidFileNameChars(), e.KeyChar) > -1) {
e.Handled = true;
System.Media.SystemSounds.Beep.Play();
noteTitleToolTip.Show("The following characters are not valid:\n\\ / : * ? < > |",
groupNoteInput, 25, -75, 2500);
return;
}
}
noteTitleToolTip.Hide(groupNoteInput);
}
Run Code Online (Sandbox Code Playgroud)
在 Windows 窗体中,当用户在控件上按下鼠标按钮时,控件将捕获鼠标;当用户释放鼠标按钮时,控件将释放鼠标。
Control 类的 Capture 属性指定控件是否已捕获鼠标。要确定控件何时丢失鼠标捕获,请处理 MouseCaptureChanged 事件。
只有前台窗口可以捕获鼠标。当后台窗口尝试捕获鼠标时,该窗口仅接收鼠标指针位于窗口可见部分内时发生的鼠标事件的消息。此外,即使前台窗口捕获了鼠标,用户仍然可以单击另一个窗口,将其带到前台。当鼠标被捕获时,快捷键不起作用。
更多这里。Windows 窗体中的鼠标捕获
| 归档时间: |
|
| 查看次数: |
1831 次 |
| 最近记录: |