水蓝 发表于 2013-1-3 15:37:04

WPF中TextBox控件对于鼠标单击获取焦点后的全选

<div id="cnblogs_post_body"><div class="cnblogs_code"> 1 void OnLostFocus(object sender, RoutedEventArgs e) 2       { 3             TextBox tb = e.Source as TextBox; 4             tb.PreviewMouseDown += new MouseButtonEventHandler(OnPreviewMouseDown); 5       } 6 7         void OnPreviewMouseDown(object sender, MouseButtonEventArgs e) 8       { 9             TextBox tb = e.Source as TextBox;10             tb.Focus();11             e.Handled = true;12       }13 14         void OnGotFocus(object sender, RoutedEventArgs e)15       {16             TextBox tb = e.Source as TextBox;17             tb.SelectAll();18             tb.PreviewMouseDown -= new MouseButtonEventHandler(OnPreviewMouseDown);19         }
页: [1]
查看完整版本: WPF中TextBox控件对于鼠标单击获取焦点后的全选