I need help trying to use the FindReplace Dialog box unless there is another way to do this. I have constructed the following code to search the text in a textbox control field and it works well. Below is the code I am using. The example is using 1 button (Button1) and 1 textbox (Textbox1):
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Specify the Type and all the Show method of the FindReplaceDialog.
ctrlFindReplace.Type = FindReplace.FindReplaceDialogType.Find
ctrlFindReplace.Show(Me)
EndSub
PrivateSub ctrlFindReplace_FindNextClick() Handles ctrlFindReplace.FindNextClick
' Handles FindNext event raised by the FindReplaceDialog. I have simplified the code here from a Microsoft sample.
Dim txtBox As System.Windows.Forms.TextBox
ActiveControl = Me.ActiveControl
IfTypeOf ActiveControl Is System.Windows.Forms.TextBox Then
TextBox1 = CType(ActiveControl, System.Windows.Forms.TextBox)
'Find the string typed in the textbox
ctrlFindReplace.FindString(TextBox1)
EndIf
EndSub
This code actually does precisely what I want it to do. It shows the dialog control, allows me to enter a text string, and automatically selects the next occurence of the string everytime the Find Next button is clicked.
Now the problem, I need this to work with a richTextBox control, not a simple textbox but the argument for the FindString method will only accept a textbox control source.
I can't believe that as powerful and versatile as VB.NET is that it has such a trivial restriction. So I must be doing something wrong. I know this dialog control has been used with MS Word which supports more than a simple text format.
Can anyone help me please??? I have tried other forums but can't seem to get an answer.
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Specify the Type and all the Show method of the FindReplaceDialog.
ctrlFindReplace.Type = FindReplace.FindReplaceDialogType.Find
ctrlFindReplace.Show(Me)
EndSub
PrivateSub ctrlFindReplace_FindNextClick() Handles ctrlFindReplace.FindNextClick
' Handles FindNext event raised by the FindReplaceDialog. I have simplified the code here from a Microsoft sample.
Dim txtBox As System.Windows.Forms.TextBox
ActiveControl = Me.ActiveControl
IfTypeOf ActiveControl Is System.Windows.Forms.TextBox Then
TextBox1 = CType(ActiveControl, System.Windows.Forms.TextBox)
'Find the string typed in the textbox
ctrlFindReplace.FindString(TextBox1)
EndIf
EndSub
This code actually does precisely what I want it to do. It shows the dialog control, allows me to enter a text string, and automatically selects the next occurence of the string everytime the Find Next button is clicked.
Now the problem, I need this to work with a richTextBox control, not a simple textbox but the argument for the FindString method will only accept a textbox control source.
I can't believe that as powerful and versatile as VB.NET is that it has such a trivial restriction. So I must be doing something wrong. I know this dialog control has been used with MS Word which supports more than a simple text format.
Can anyone help me please??? I have tried other forums but can't seem to get an answer.