在光标位置打开一个小浮动窗口

我正在写一个小概念validation,要求我听一些按键组合,当按下时会在当前光标位置下面打开一个小的WPF/WinForms窗口。 我更像是一个网络人,所以我从这开始就遇到了麻烦。

谁能指出我正确的方向? 或者提供一些资源/示例?

谢谢。

尝试WPF的这个例子。 按Enter键可提前显示Popup窗口,接收鼠标光标的坐标。

XAML

          

Code-behind

 public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Window_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { PopupWindow.IsOpen = true; var point = Mouse.GetPosition(Application.Current.MainWindow); PopupWindow.HorizontalOffset = point.X; PopupWindow.VerticalOffset = point.Y; } } } 

Edit: An easier solution

您可以为Popup设置Placement="Mouse" ,而不是接收鼠标的坐标:

XAML

        

Code-behind

 public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Window_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { PopupWindow.IsOpen = true; } } }