RSS Forums RSS
Please support our VB.NET advertiser: Programming Forums
Views: 2054 | Replies: 13 | Thread Tools  Display Modes
Reply
Join Date: Sep 2007
Posts: 36
Reputation: Webbsta is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
Webbsta Webbsta is offline Offline
Light Poster

"Find next" dialog for textbox

  #1  
Jan 4th, 2008
Hi, I'm trying to work out a way i can create my own "find..." or "find next" dialog for a textbox, because i don't think Vb.net has one that you can use, and its vital that i manage to get this otherwise the program wont be much use when editing large documents and you don't want to spend half an hour finding a sentence or a word. Does anybody know of a way i can create my own using strings or maybe something else, i did think about using the split() method and i wouldn't know where to go after that, thanks.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2002
Location: West Virginia
Posts: 434
Reputation: waynespangler is on a distinguished road 
Rep Power: 7
Solved Threads: 50
waynespangler waynespangler is online now Online
Posting Pro in Training

Re: "Find next" dialog for textbox

  #2  
Jan 5th, 2008
If you are using richtextbox then it has its own find method. Just keep track where you started so you know when you went through the whole document. Keep track of where you currentlly are to start your next find.
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote  
Join Date: Sep 2007
Posts: 36
Reputation: Webbsta is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
Webbsta Webbsta is offline Offline
Light Poster

Re: "Find next" dialog for textbox

  #3  
Jan 5th, 2008
No, its for a textbox, not a richtextbox.
Reply With Quote  
Join Date: Aug 2005
Posts: 4,844
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 325
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: "Find next" dialog for textbox

  #4  
Jan 5th, 2008
It would make more sense having a richtext box, especially since it would be easy to highlight the words.
*Voted best profile in the world*
Reply With Quote  
Join Date: Sep 2007
Posts: 36
Reputation: Webbsta is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
Webbsta Webbsta is offline Offline
Light Poster

Re: "Find next" dialog for textbox

  #5  
Jan 12th, 2008
OK, how do i use the find method on the rtb, iv tried numerous ways but it doesn't seem to work, thanks.
Reply With Quote  
Join Date: Aug 2005
Posts: 4,844
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 325
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: "Find next" dialog for textbox

  #6  
Jan 13th, 2008
*Voted best profile in the world*
Reply With Quote  
Join Date: Sep 2007
Posts: 36
Reputation: Webbsta is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
Webbsta Webbsta is offline Offline
Light Poster

Re: "Find next" dialog for textbox

  #7  
Jan 13th, 2008
Thats VB6... i tried the vb6 code upgrader but it didn't work.
Reply With Quote  
Join Date: Dec 2002
Location: West Virginia
Posts: 434
Reputation: waynespangler is on a distinguished road 
Rep Power: 7
Solved Threads: 50
waynespangler waynespangler is online now Online
Posting Pro in Training

Re: "Find next" dialog for textbox

  #8  
Jan 14th, 2008
Add a form to your project and call it frmFind or something like that (see attached image).
My richtextbox is called Editor.
Add this code.
Public Class frmFind
    Private PlaceHolder As Integer

    Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click
        Dim x As Integer
        Dim opt As RichTextBoxFinds = 0
        If ckCaseSensitive.Checked Then opt = opt Or RichTextBoxFinds.MatchCase
        If ckWholeWord.Checked Then opt = opt Or RichTextBoxFinds.WholeWord
        x = Form1.Editor.Find(txtFind.Text, PlaceHolder, opt)
        If x < 0 Then
            If MessageBox.Show("There is no more occurances of " & txtFind.Text & vbCrLf & "Start at begining?", "Can't Find", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then
                PlaceHolder = 0
                btnFind.PerformClick()
            End If
        End If
    End Sub

    Private Sub btnReplace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReplace.Click
        Form1.Editor.SelectedText = txtReplace.Text
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub

    Private Sub btnFindNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindNext.Click
        PlaceHolder = Form1.Editor.SelectionStart + 1
        btnFind.PerformClick()
    End Sub

    Private Sub frmFind_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PlaceHolder = Form1.Editor.SelectionStart

    End Sub

    Private Sub btnReplaceAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReplaceAll.Click
        Dim x As Integer
        Dim opt As RichTextBoxFinds = 0
        If ckCaseSensitive.Checked Then opt = opt Or RichTextBoxFinds.MatchCase
        If ckWholeWord.Checked Then opt = opt Or RichTextBoxFinds.WholeWord
        PlaceHolder = 0
        Do
            x = Form1.Editor.Find(txtFind.Text, PlaceHolder, opt)
            If x < 0 Then
                Exit Do
            Else
                Form1.Editor.SelectedText = txtReplace.Text
            End If
            PlaceHolder = Form1.Editor.SelectionStart + 1
        Loop

    End Sub
End Class
and call it like this
        frmFind.txtFind.Text = Editor.SelectedText
        frmFind.ShowDialog()
Attached Images
File Type: gif frmFind.gif (18.3 KB, 5 views)
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote  
Join Date: Aug 2005
Posts: 4,844
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 325
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: "Find next" dialog for textbox

  #9  
Jan 14th, 2008
Originally Posted by Webbsta View Post
Thats VB6... i tried the vb6 code upgrader but it didn't work.


Yeah sorry, I missed that. See the above example though, it looks good.
*Voted best profile in the world*
Reply With Quote  
Join Date: Feb 2008
Posts: 3
Reputation: hitnrun is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
hitnrun hitnrun is offline Offline
Newbie Poster

Re: "Find next" dialog for textbox

  #10  
Feb 5th, 2008
I have used the code above, but the richtextbox on the main screen does not reflect the change till I close the find screen. What do I need to change so it will.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the VB.NET Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 6:48 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC