After the WPF textbox gets the focus, select all text in the text box.

Source: Internet
Author: User

Textbox. gotfocus event processing textbox. selectall () is not acceptable, so the processing will happen:
1) textbox1 currently has no focus and the content is sometext.
2) Click textbox1. If the clicked point is within sometext, all options after sometext is selected are canceled. If the clicked point is outside sometext, nothing will happen, no selected content.

 

The solution is as follows:

 

Public partial class mainwindow: window {public mainwindow () {initializecomponent (); like_textbox.previewmousedown + = new mousebuttoneventhandler (like_textbox_previewmousedown); // note, registration of this event must be performed before like_textbox obtains the Focus + = new routedeventhandler (handler); handler + = new routedeventhandler (handler);} void like_textbox_lostfocus (Object sender, routedeventargs E) {callback + = new mousebuttoneventhandler (like_textbox_previewmousedown);} void like_textbox_previewmousedown (Object sender, mousebuttoneventargs e) {like_textbox.focus (); E. handled = true;} void like_textbox_gotfocus (Object sender, routedeventargs e) {like_textbox.selectall (); callback-= new mousebuttoneventhandler (like_textbox_previewmousedown );}}

 

After the WPF textbox gets the focus, select all text in the text box.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.