|
-
Sep 28th, 2008, 09:54 AM
#1
Thread Starter
Addicted Member
[2008] RichTextBox Replace Programmatically
I have a RTB that loads data from a file like this in the Load event of the Form2
Code:
Me.rtb_cerere.LoadFile(Application.StartupPath & "\ceelceur.rtf")
After i load this file i want to replace some key words with a specified text but here i'm stuck...
I use this...
Code:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim PozitieCurenta As Integer = Me.rtb_cerere.SelectionStart
Dim SelectieCurenta As Integer = Me.rtb_cerere.SelectionLength
Dim CuvantCheie As String = "{1}"
Me.rtb_cerere.Select(StartPosition - 1, CuvantCheie.Length)
Me.rtb_cerere.ScrollToCaret()
Me.Focus()
Me.rtb_cerere.Rtf = Replace(Me.rtb_cerere.Rtf, Trim(CuvantCheie), Trim("TEST"))
Me.rtb_cerere.SelectionStart = PozitieCurenta
Me.rtb_cerere.SelectionLength = SelectieCurenta
Me.Focus()
End Sub
How can i replace this {1} with "TEST" ? I have spend 2 days and i'm lost in the space!
Thanks...
I'm still learning VB.NET
Sorry for my bad english
Thanks for your help
-
Sep 28th, 2008, 10:29 AM
#2
Re: [2008] RichTextBox Replace Programmatically
Code:
Dim testRTB As New RichTextBox
testRTB.Text = "1234{1}56789abcdefghi{1}jklmnopqrstuvwxyz"
Debug.WriteLine(testRTB.Text)
testRTB.Text = testRTB.Text.Replace("{1}", "Test")
Debug.WriteLine(testRTB.Text)
debug output
1234{1}56789abcdefghi{1}jklmnopqrstuvwxyz
1234Test56789abcdefghiTestjklmnopqrstuvwxyz
-
Sep 28th, 2008, 10:53 AM
#3
Thread Starter
Addicted Member
-
Sep 28th, 2008, 11:00 AM
#4
Re: [2008] RichTextBox Replace Programmatically
try this:
vb Code:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim PozitieCurenta As Integer = Me.rtb_cerere.SelectionStart
Dim SelectieCurenta As Integer = Me.rtb_cerere.SelectionLength
Dim CuvantCheie As String = "{1}"
Dim startAt As Integer = 0
Do While Me.rtb_cerere.Text.IndexOf(CuvantCheie, startAt) <> -1
Me.rtb_cerere.SelectionStart = Me.rtb_cerere.Text.IndexOf(CuvantCheie, startAt)
Me.rtb_cerere.SelectionLength = CuvantCheie.Length
startAt = Me.rtb_cerere.Text.IndexOf(CuvantCheie, startAt) + CuvantCheie.Length
Me.rtb_cerere.SelectedText = "New Text"
Loop
Me.rtb_cerere.SelectionStart = PozitieCurenta
Me.rtb_cerere.SelectionLength = SelectieCurenta
Me.Focus()
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 28th, 2008, 11:10 AM
#5
Thread Starter
Addicted Member
-
Sep 28th, 2008, 12:02 PM
#6
Re: [2008] RichTextBox Replace Programmatically
 Originally Posted by Alexandru_mbm
Thanks alot!
It's working but i have another problem now...
The RTB text loaded from the file is formated and if i use that code the hole text will not keep his properties.
Any ideea about this ?!
what do you mean? if you can post what you tried.
-
Sep 28th, 2008, 12:04 PM
#7
Re: [2008] RichTextBox Replace Programmatically
using replace on the rtb.text removes all the text formatting
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 28th, 2008, 12:21 PM
#8
Re: [2008] RichTextBox Replace Programmatically
if all else fails i should, read the destructions, hmm, i mean instructions
-
Sep 28th, 2008, 02:06 PM
#9
Thread Starter
Addicted Member
Re: [2008] RichTextBox Replace Programmatically
I have tried to take values from another form (Form1 wich is a MDI Child) and use it into another form (Form2 - that uses the RTB code) but it seems it's not working like in VB6 ?
Code:
Me.rtb_cerere.SelectedText = frm_eliberare_cerere_certificat_urbanism.txt_nr_cerere.Text
Or what i am doing wrong ?
Last edited by Alexandru_mbm; Sep 28th, 2008 at 04:20 PM.
I'm still learning VB.NET
Sorry for my bad english
Thanks for your help
-
Sep 28th, 2008, 04:28 PM
#10
Thread Starter
Addicted Member
-
Sep 29th, 2008, 02:23 PM
#11
Thread Starter
Addicted Member
Re: [2008] RichTextBox Replace Programmatically
I have another problem with this code...
I take values from the Form1 by using
Code:
Public Shared SHR_SatSolicitant as String
SHR_SatSolicitant = Me.txt_box1.text
The problem is when i use the code (down) to replace the string "{13}" if the Form1 SHR_SatSolicitant is EMPTY is not replacing me with "" (empty).
Code:
Dim STR_SatSolicitant As String = "{13}"
If frm_eliberare_cerere_certificat_urbanism.SHR_SatSolicitant = "" Then
Do While Me.rtb_cerere.Text.IndexOf(STR_SatSolicitant, startAt) <> -1
Me.rtb_cerere.SelectionStart = Me.rtb_cerere.Text.IndexOf(STR_SatSolicitant, startAt)
Me.rtb_cerere.SelectionLength = STR_SatSolicitant.Length
startAt = Me.rtb_cerere.Text.IndexOf(STR_SatSolicitant, startAt) + STR_SatSolicitant.Length
Me.rtb_cerere.SelectedText = Me.rtb_cerere.SelectedText.Replace(Me.rtb_cerere.SelectedText, "")
Loop
Else
Do While Me.rtb_cerere.Text.IndexOf(STR_SatSolicitant, startAt) <> -1
Me.rtb_cerere.SelectionStart = Me.rtb_cerere.Text.IndexOf(STR_SatSolicitant, startAt)
Me.rtb_cerere.SelectionLength = STR_SatSolicitant.Length
startAt = Me.rtb_cerere.Text.IndexOf(STR_SatSolicitant, startAt) + STR_SatSolicitant.Length
Me.rtb_cerere.SelectedText = ", satul " & frm_eliberare_cerere_certificat_urbanism.SHR_SatSolicitant
Loop
End If
What shold i do ? Thanks again and i'll wait again your big help!
Last edited by Alexandru_mbm; Sep 29th, 2008 at 03:13 PM.
I'm still learning VB.NET
Sorry for my bad english
Thanks for your help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|