Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how can I replace text in richtextbox?

Posted on 2004-03-29
5
Medium Priority
?
438 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
5 Comments
 
LVL 48

Accepted Solution

by:
Mikal613 earned 2000 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:Fahad Mukhtar
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

963 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