![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Problem with autoselecting text on getting focus For our application, the desired behavior is when a text box is getting a focus, all text within that text box is automatically selected, so user can just start typing, saving keystrokes. I couldn't find a property that controls this behavior, so I just attached an event to the text box: edPrice.GotFocus += delegate(object sender, RoutedEventArgs e) { edPrice.SelectAll(); }; Unfortunately, this works only if the focus is received through keyboard navigation, if a text box is selected with a mouse, the selection disappears as soon as mouse button is released. Handling the PreviewMouseLeftButtonUp (setting event argument's Handled to true) helped, but completely broke mouse navigation. Re-selecting the text in MouseLeftButtonUp also got me nowhere. Any suggestions? |
| | #2 (permalink) |
| Guest | Re: Problem with autoselecting text on getting focus Hi, You could try something like the following, it's simple, but has problem when losing the focus with the mouse. The next item will require two mouse clicks instead of one to get the focus out of the MyTextBox instance. class MyTextBox: TextBox { bool isGettingFocus; protected override void OnPreviewMouseUp(System.Windows.Input.MouseButtonEventArgs e) { if (isGettingFocus) { isGettingFocus = false; e.Handled = true; } else base.OnPreviewMouseUp(e); } protected override void OnGotKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e) { base.OnGotKeyboardFocus(e); this.SelectAll(); } protected override void OnPreviewGotKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e) { base.OnPreviewGotKeyboardFocus(e); isGettingFocus = true; } } Luc |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Text display problem HELP PLEASE | Ray | Vista General | 10 | 07-25-2008 07:47 PM |
| WPF ListView focus problem. | Igor | .NET General | 0 | 03-05-2008 07:01 AM |
| I have a problem with text-settings in Paint! | indiced | Vista music pictures video | 6 | 01-08-2008 03:00 PM |
| keyboard problem: text goes everywhere | AndrewV | Vista hardware & devices | 4 | 08-05-2007 11:16 AM |
| Text to Speech problem | treesy | Vista General | 2 | 04-11-2007 04:42 AM |