简体   繁体   中英

Simple Find & Replace in a TextBox

Ok, I have done this a gazillion times in WinForms apps, but this just doesn't work in Metro apps. I'm not going to post the code I have because I believe it will just be confusing (since this same code doesn't work for anybody else's metro apps).

What I am trying to do is allow someone to just enter a string of text into a textbox and then Find that text and highlight/select it in the main textbox. But it seems to be near impossible to accomplish.

I really don't know what to do. I'm beginning to think it's not possible :-/

You should check RichEditBox

To select your text just use:

var sel = myRichEdit.Document.Selection;
    sel.StartPosition = 0;
    sel.EndPosition = 10;

Just replace the values with your selection. To search specyfic text in your RichEditBox just use String method IndexOf . This method sould return index of searched value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM