我有一个带有简单气球工具提示的 Windows 窗体应用程序。根据应用程序在桌面上的窗口位置和鼠标光标位置,气球“提示”(或气球指向箭头)可能指向也可能不指向我想要的位置。
例如,我的应用吸附到桌面两侧,当它吸附到右侧时,如果鼠标光标低于右侧 100 像素,气球“提示”将指向错误的位置。但是,如果鼠标光标在其他任何地方,它将指向正确的位置。
在这种情况下,我想将鼠标光标位置(而不实际更改鼠标光标位置)伪造到其他地方,这样问题就不会发生。
这可能吗?我怎样才能做到这一点?
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);
}
最佳答案
我不太清楚为什么需要设置光标位置,因为您可以将工具提示设置为出现在您指定的位置,而不一定是鼠标所在的位置。
例如:
tooltip1.Show("My tip", controlOnWhichToShow, 15, 15);
将在 controlOnWhichToShow 的左上角显示提示,距边缘 15 点。
如果我误解了你,请说明鼠标位置在哪个时间点被使用。
关于c# - 如何在 Windows 窗体 C# 中伪造鼠标光标位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3484806/