WPF TextBox string Search, scrolling to the current line

Source: Internet
Author: User

1 //Execution Events2 Private voidButton_Click (Objectsender, RoutedEventArgs e)3         {4 5             if(Txtstr. Text = ="")6             {7MessageBox.Show ("the query string is empty! ");8                 return;9             }Ten cxtxt_string (); One         } A  - //Execution Method -         intindex =0;//Search starting from the No. 0 string the          Public voidcxtxt_string () -         { -             stringstr = TextBox1.Text;//set the string you want to find -index = textBox2.Text.IndexOf (str, index);//returns the index position of str in TextBox1 +             if(Index <0)//If no string is found, the return -             { +index =0; ATextbox2.selectionstart =0; atTextbox2.selectionlength =0; -MessageBox.Show ("has reached the end"); -                 return; -             } -Textbox2.selectionstart = index;//set where you want the selected string to start -Textbox2.selectionlength = str. Length;//set the end position of the string to be selected inindex++; -Textbox2.focus ();//Set Focus to  +             //int rows = Textbox2.getfirstvisiblelineindex ();//get the row index of the first character in a visible text box -             intline = Textbox2.getlineindexfromcharacterindex (index);//returns the line number where the specified string index is located the             //Debug.WriteLine (Rows + ",," + line); *             intLastLine =Textbox2.getlastvisiblelineindex (); $             if(Line >lastline)Panax Notoginseng             { -Textbox2.scrolltoline (lastline+1);//Scroll to the specified row index in the view the             } +         } A     } the}

WPF finds strings in a TextBox and scrolls automatically to the line where the string is located

WPF TextBox string Search, scrolling to the current line

Related Article

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.