【问题标题】:Visual Basics: How to do a Find and Replace either on the selected text or the whole document?Visual Basics:如何对选定文本或整个文档进行查找和替换?
【发布时间】:2012-12-03 13:20:23
【问题描述】:

到目前为止,我已经能够对整个文本进行查找和替换。

Private Sub btnFFindNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFFindNext.Click

    Dim search As String
    Dim length As String

    search = textToFind.Text 
    length = textToFind.Text.Length

        lastposition = RichTextBox.Find(textToFind.Text, lastposition, RichTextBoxFinds.None)

    RichTextBox.SelectionStart = lastposition
    RichTextBox.SelectionLength = length
    lastposition = lastposition + 1

但是,我现在需要使它成为可能,以便如果用户选择某些文本,则仅对该选择执行查找和替换。

我该怎么做?

【问题讨论】:

    标签: vb.net visual-studio-2010 replace


    【解决方案1】:

    您可以将 ricthTextBox.Find> 与 start 和 end 参数一起使用(与您使用的类似)。
    可以从richTextBox的事件(SelectionChanged)中取第一个起点和终点

    告诉我进展如何。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-02
      • 2019-10-29
      • 1970-01-01
      • 2018-12-31
      • 2013-07-18
      • 2021-04-27
      • 1970-01-01
      相关资源
      最近更新 更多