Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a program that open encrypted INI files (used in my other program as a settings).
In my Decrypt Exe (reading the INI file, decrypt it and able to edit the file and save as encrypted text). Other functionalities is Find.

My problem is sometimes the selected text when finish clicking the button Find Text is hidden by the frmFind. I want to set the position(top, left) when that happens. Many known application has this function.

Please Help... Thanks

This is my code in finding text, I don't know if there's a better solution on this
VB
'CODE IN BUTTON "FIND NEXT" ALSO IN frmFind
Dim startText As String
Dim endText As String
Dim findInt As Integer
Dim searchText As String
searchText = LCase(txtFind.Text)
If Option1.Value Then
    startText = LCase(Left(frmDecrypt.RichTextBox1.Text, frmDecrypt.RichTextBox1.SelStart))
    endText = LCase(Mid(frmDecrypt.RichTextBox1.Text, Len(startText)))
    findInt = InStr(startText, searchText)
    If findInt > 0 Then
        frmDecrypt.RichTextBox1.SelStart = findInt - 1
        frmDecrypt.RichTextBox1.SelLength = Len(searchText)
    Else
        frmFind.Visible = False
        MsgBox "The specified region has been reach.", vbCritical
        frmFind.Visible = True
    End If
Else
    startText = LCase(Left(frmDecrypt.RichTextBox1.Text, frmDecrypt.RichTextBox1.SelStart + frmDecrypt.RichTextBox1.SelLength))
    endText = LCase(Mid(frmDecrypt.RichTextBox1.Text, Len(startText) + 1))
    findInt = InStr(endText, searchText)
    If findInt > 0 Then
        frmDecrypt.RichTextBox1.SelStart = findInt + Len(startText) - 1
        frmDecrypt.RichTextBox1.SelLength = Len(searchText)
    Else
        frmFind.Visible = False
        MsgBox "The specified region has been reach.", vbCritical
        frmFind.Visible = True
    End If
End If
frmDecrypt.SetFocus
Posted
Updated 23-Jan-14 1:50am
v2

1 solution

VB
' top left of screen
frmFind.Left = 0
frmFind.Top = 0
' or top left of current form
frmFind.Left = ME.Left
frmFind.Top = ME.Top
 
Share this answer
 
Comments
hansoctantan 23-Jan-14 7:39am    
i can't just set the form to a random point, its possible that the selected text(find text) is on the top left on the RichTextBox. 0 left and 0 right will cover it.
hansoctantan 23-Jan-14 7:41am    
not to mention I'm adding the codes to frmFind so ME.Left is equal frmFind.Left

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900