User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 427,221 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,263 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 1593 | Replies: 13
Reply
Join Date: Sep 2007
Posts: 35
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: 388
Reputation: waynespangler is on a distinguished road 
Rep Power: 6
Solved Threads: 40
waynespangler waynespangler is offline Offline
Posting Whiz

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: 35
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,782
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: 319
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.
I'm not a programmer. My attitude starts with ignorance, holds steady at conversation, and ends with a trip to the hospital. Get used to it.
Reply With Quote  
Join Date: Sep 2007
Posts: 35
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,782
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: 319
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: "Find next" dialog for textbox

  #6  
Jan 13th, 2008
I'm not a programmer. My attitude starts with ignorance, holds steady at conversation, and ends with a trip to the hospital. Get used to it.
Reply With Quote  
Join Date: Sep 2007
Posts: 35
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: 388
Reputation: waynespangler is on a distinguished road 
Rep Power: 6
Solved Threads: 40
waynespangler waynespangler is offline Offline
Posting Whiz

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,782
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: 319
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.
I'm not a programmer. My attitude starts with ignorance, holds steady at conversation, and ends with a trip to the hospital. Get used to it.
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.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 11:24 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC