本文介绍了如何在控件外捕获Mouse Down事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Mouse Capture不起作用:
public partial class MainWindow:Window
{
public MainWindow( )
{
InitializeComponent();
Button button1 = new Button();
button1.Width = 50 ;
button1.Height = 20 ;
this .Content = button1;
Mouse.Capture(button1);
button1.PreviewMouseDown + = Down;
}
private void Down( object sender,MouseButtonEventArgs e)
{
MessageBox.Show( Hello World!); // 不显示
}
}
解决方案
Mouse Capture doesn't work:
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); Button button1 = new Button(); button1.Width = 50; button1.Height = 20; this.Content = button1; Mouse.Capture(button1); button1.PreviewMouseDown += Down; } private void Down(object sender, MouseButtonEventArgs e) { MessageBox.Show("Hello World!"); // doesn't show } }
解决方案
这篇关于如何在控件外捕获Mouse Down事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!