void textBox1_GotFocus(object sender, EventArgs e) { // Select all text only if the mouse isn't down. // This makes tabbing to the textbox give focus. if (MouseButtons == MouseButtons.None) { box.SelectAll(); alreadyFocused = true; } }
internal static void SelectAllText(this System.Windows.Controls.TextBox tb) { tb.Dispatcher.BeginInvoke( new Action(delegate { tb.SelectAll(); }), System.Windows.Threading.DispatcherPriority.Input); }
/// <summary> /// Handles key tip pressed /// </summary> public override void OnKeyTipPressed() { if (!IsTemplateValid()) return; // Use dispatcher to avoid focus moving to backup'ed element // (focused element before keytips processing) Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, (ThreadStart)(() => { textBox.SelectAll(); textBox.Focus(); })); base.OnKeyTipPressed(); }
static void frameworkElement_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) { if (((bool)e.NewValue)) { if (sender is System.Windows.Controls.TextBox) { System.Windows.Controls.TextBox textBox = sender as System.Windows.Controls.TextBox; if (textBox != null) { textBox.SelectAll(); } } ((FrameworkElement)sender).Focus(); } }
public static bool ValidateDouble(this TextBox textBox, bool ignoreIfEmpty) { if (ignoreIfEmpty && string.IsNullOrEmpty(textBox.Text)) { return(true); } if (!double.TryParse(textBox.Text, NumberStyles.Number, StreamDeckConstants.DoubleCultureInfo, out var result)) { MessageBox.Show("Please enter valid number.", "Invalid number.", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox.SelectAll(); return(false); } return(true); }
private void TextBox_SelectAllOnFocus(object sender, RoutedEventArgs e) { System.Windows.Controls.TextBox textbox = (System.Windows.Controls.TextBox)e.Source; textbox.SelectAll(); }
private void LocationState_GotKeyboardFocus(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e) { System.Windows.Controls.TextBox tb = (System.Windows.Controls.TextBox)sender; Dispatcher.BeginInvoke(new Action(() => tb.SelectAll())); }