标签:btn set release dde 实现 user led col rev
原文:[WPF]实现TextBox文本框单击全选
        /// <summary>
        /// Void:设置获取焦点时全选文本
        /// </summary>
        /// <param name="textbox">指定文本框</param>
        public void SetSelectionAllOnGotFocus(TextBox textbox)
        {
            MouseButtonEventHandler _OnPreviewMouseDown = (sender, e) =>
            {
                TextBox box = e.Source as TextBox;
                box.Focus();
                e.Handled = true;
            };
            RoutedEventHandler _OnLostFocus = (sender, e) =>
            {
                TextBox box = e.Source as TextBox;
                box.PreviewMouseDown += _OnPreviewMouseDown;
            };
            RoutedEventHandler _OnGotFocus = (sender, e) =>
            {
                TextBox box = e.Source as TextBox;
                box.SelectAll();
                box.PreviewMouseDown -= _OnPreviewMouseDown;
            };
            textbox.PreviewMouseDown += _OnPreviewMouseDown;
            textbox.LostFocus += _OnLostFocus;
            textbox.GotFocus += _OnGotFocus;
        }
 
标签:btn set release dde 实现 user led col rev
原文地址:https://www.cnblogs.com/lonelyxmas/p/12075360.html