Jump to content

[Resolvido] Encontrar palavra em richtextbox


leo2012

Recommended Posts

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 Dim index As Integer = 0
 Dim lastIndex As Integer = RichTextBox1.Find(TextBox1.Text, RichTextBoxFinds.Reverse)
 While index < lastIndex
	 index = RichTextBox1.Find(TextBox1.Text, index, RichTextBoxFinds.None)
	 RichTextBox1.SelectionBackColor = Color.Yellow
	 RichTextBox1.SelectionColor = Color.Red
	 index += 1
 End While
End Sub
Edited by Caça
Link to comment
Share on other sites

Hello.

Com a richtextbox do windows.forms um método simples para isso é guardar o texto num ficheiro.

O 'undo' equivale a carregar a richtb a partir do ficheiro.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 Dim index As Integer = 0
 Dim lastIndex As Integer = RichTextBox1.Find(TextBox1.Text, RichTextBoxFinds.Reverse)
 'criar ficheiro na pasta do utilizador
 RichTextBox1.SaveFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) & "\TesteRich.rtf", RichTextBoxStreamType.RichNoOleObjs)
 While index <= lastIndex
	 index = RichTextBox1.Find(TextBox1.Text, index, RichTextBoxFinds.None)
	 RichTextBox1.SelectionBackColor = Color.Yellow
	 RichTextBox1.SelectionColor = Color.Red
	 index += 1
 End While
End Sub
'Repor situação anterior
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
 Try
	 RichTextBox1.LoadFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) & "\TesteRich.rtf", RichTextBoxStreamType.RichText)
	 Kill(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) & "\TesteRich.rtf")
 Catch ex As Exception
	 MsgBox("Ficheiro de carregamento não encontrado!")
 End Try
End Sub
Edited by Caça
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.