Solved

how can I replace text in richtextbox?

Posted on 2004-03-29
5
435 Views
Last Modified: 2008-02-01
Hi, all
How can I replace TEXT in RichTEXT box??
I can not find to method in Richtexbox to replace TEXT?
Can anyone provide some coding?
0
Comment
Question by:davidlam8888
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 48

Accepted Solution

by:
Mikal613 earned 500 total points
ID: 10708510
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 10708522
VB.net has introduced a number of changes to the way you access the RichTextBox's properties. SelUnderline, SelBold, SelStrikethrough etc are now available in the

richTextBox1.SelectionFont

property. For example, in VB.net, use

richTextBox1.SelectionFont.Underline

instead of

richTextBox1.SelUnderline

0
 
LVL 6

Expert Comment

by:KarunSK
ID: 10708580
Use this:

        Dim strFind As String = "stringtofind"
        Dim iPos As Integer = RichTextBox1.Find(strFind)
        RichTextBox1.Select(iPos, strFind.Length)
        RichTextBox1.SelectedText = "stringtoreplace"

Karun.
0
 
LVL 19

Expert Comment

by:Desp
ID: 10711685
try this:

assuming the string you want to search in richtextbox1 is written in textBox1 and the button1 is the button which will tell you the index ...

set your richTextBox.HideSelection property to false( which is true by default)  so that this code can show you the occurences of the required text..


Dim position As Integer = 0 ' in the declaration section of your form class

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

       Dim index As Integer = RichTextBox1.Text.IndexOf(TextBox1.Text, position)' get the index of next occurance

       If (index > -1) Then' if the word is found
           RichTextBox1.Select(index, TextBox1.Text.Length) ' select and show the found text in the richtextbox

' You can also remove the line below to have the "FIND" Feature only instead of "FIND and REPLACE" feature
          RichTextBox1.SelectedText = "New Word" 'put your word(s) that you want tyo replace

           position = index + TextBox1.Text.Length        'update the position        

        Else
           MessageBox.Show("The string " & TextBox1.Text & " cannot be found")
        End If


   End Sub
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question