robertb_NZ
Well-known member
I am trying to add Find and Replace functions to a RichTextBox editor (Jazz Workbench). I found an example that did what I wanted, downloaded the sample application, and copied frmFind into my project. It works perfectly except that: Find doesn't highlight the found text until you click the parent form. When you do frmFind remains visible (correct), but is no longer the active screen.
The exact same code works perfectly when I run the sample application in its original form; frmFind remains the active form, but the found text is highlighted, just as in Notepad and Visual Studio.
To simplify this problem I created frmFind2 with nothing but a textbox and a button, and this code: -
Public Class frmFind2
frmFind2 shows the same incorrect behavior as frmFind, requiring the parent form to be clicked to show the highlighting. Otherwise the search behaves perfectly.
I've spend several hours experimenting and reading MSDN, but nothing I've tried helps. I hope somebody can help me.
Thank you, Robert.
The exact same code works perfectly when I run the sample application in its original form; frmFind remains the active form, but the found text is highlighted, just as in Notepad and Visual Studio.
To simplify this problem I created frmFind2 with nothing but a textbox and a button, and this code: -
Public Class frmFind2
Private Sub btnFind_Click(sender As System.Object, e As System.EventArgs) Handles btnFind.Click
End ClassDim iOptions As Integer = 0
Dim lStartPos, lEndPos As Long
Dim WKB As JazzWorkbench = Startup.JazzWorkbench
If WKB IsNot Nothing Then
End SubDim lStartPos, lEndPos As Long
Dim WKB As JazzWorkbench = Startup.JazzWorkbench
If WKB IsNot Nothing Then
lStartPos = WKB.ProgramArea.SelectionStart + WKB.ProgramArea.SelectionLength
lEndPos = WKB.ProgramArea.TextLength
If WKB.ProgramArea.Find(txtFind.Text, lStartPos, lEndPos, iOptions) = -1 Then
End IflEndPos = WKB.ProgramArea.TextLength
If WKB.ProgramArea.Find(txtFind.Text, lStartPos, lEndPos, iOptions) = -1 Then
MessageBox.Show("No more occurences of '" & txtFind.Text & "' have been found.", "Find result", MessageBoxButtons.OK, MessageBoxIcon.Information)
End IffrmFind2 shows the same incorrect behavior as frmFind, requiring the parent form to be clicked to show the highlighting. Otherwise the search behaves perfectly.
I've spend several hours experimenting and reading MSDN, but nothing I've tried helps. I hope somebody can help me.
Thank you, Robert.