Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: search result in text box


Message #1 by maryam a <m_ctrl_a@y...> on Thu, 30 Jan 2003 04:03:09 -0800 (PST)
The following code assumes that the user has selected an area of the rich
text box, and clicked a button to change any one of the properties shown in
the With/EndWith block.  The button would invoke the following:

    ' Initialize Font Common Dialog
    CommonDialog1.Flags = cdlCFEffects Or cdlCFBoth
    CommonDialog1.ShowFont
    ' Set text formatting
    With rtbComments
        .SelBold = CommonDialog1.FontBold
        .SelItalic = CommonDialog1.FontItalic
        .SelUnderline = CommonDialog1.FontUnderline
        .SelFontName = CommonDialog1.FontName
        .SelFontSize = CommonDialog1.FontSize
        .SelColor = CommonDialog1.Color
    End With

In your case, if you only want to change the color, say, of words being
searched for, you could do something like this:

Start a new project and put a RichTextBox control on Form1, then paste the
following into Form1's code:

Option Explicit

Private Sub Form_Activate()
    RichTextBox1.Text = "Da do ron ron ron, da do ron ron."
    Call psSearch("do")
End Sub

Private Sub psSearch(ByVal aSearchText As String)
Dim lPointer As Long
Dim lFound   As Long

    lPointer = 1
    Do While lPointer < Len(RichTextBox1.Text)
        lFound = InStr(lPointer, RichTextBox1.Text, aSearchText,
vbTextCompare)
        If lFound > 0 Then
            RichTextBox1.SelStart = lFound - 1
            RichTextBox1.SelLength = Len(aSearchText)
            RichTextBox1.SelColor = vbRed
            lPointer = lFound + Len(aSearchText)
        Else
            Exit Do
        End If
    Loop
End Sub

Hope this helps,

Pete

-----Original Message-----
From: maryam a [mailto:m_ctrl_a@y...]
Sent: Thursday, January 30, 2003 1:15 PM
To: professional vb
Subject: [pro_vb] RE: search result in text box



hi
i will be so tankfull ,if u would show some example of Rich text
tnx
Maryam
 "Peter N. Kipe" <pkipe@c...> wrote:With a textbox, you would
only be able to cause the word to appear
selected -- i.e. white characters on a blue background. Any action the user
were to take in the textbox could change the highlighting, or remove it.

But if you're using a Rich Text Box, you CAN change the color, font, weight,
etc. of any or all text. Let me know if you want examples of how to do
that.

Pete

-----Original Message-----
From: maryam a [mailto:m_ctrl_a@y...]
Sent: Thursday, January 30, 2003 7:03 AM
To: professional vb
Subject: [pro_vb] search result in text box



hi

i have some text in text box and i seach an specified word with Instr() and
i know that it gives me the index of found word in the text box,i want to
know is there any solution that i can remark the word i found, for example
change it's color?

tnx

Maryam





---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now





---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now



  Return to Index