[英]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. 好的,我已经在WinForms应用程序中完成了无数次尝试,但这在Metro应用程序中却行不通。 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).
我不打算发布我拥有的代码,因为我相信它只会令人困惑(因为该代码对其他任何人的Metro应用都无效)。
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 您应该检查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 .
要在RichEditBox中搜索特定文本,只需使用String方法IndexOf即可 。 This method sould return index of searched value.
该方法为搜索值提供了返回索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.