15-09-16, 02:17 AM
(آخر تعديل لهذه المشاركة : 15-09-16, 02:22 AM {2} بواسطة silverlight.)
أتمني إن الكود التالي سوف يعطيك فكرة جيدة عن كيفية البحث عن كلمة في RichTextBox
افتح مشروع و أضف الي الفورم RichTextBox و باتون ثم اكتب الكود بالشكل التالي
الكود سوف يجد لك الكلمة التي تبحث عنها
وهنا انا قمت بالبحث عن كلمة vb4arab
افتح مشروع و أضف الي الفورم RichTextBox و باتون ثم اكتب الكود بالشكل التالي
الكود سوف يجد لك الكلمة التي تبحث عنها
وهنا انا قمت بالبحث عن كلمة vb4arab
PHP كود :
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim s As String = "vb4arab demo, The fox knows to jump but how, how he jump?, and how he learned to jumb bla bla bla bla, vb4arab demo"
RichTextBox1.Text = s
End Sub
Private Function TryFindString(stringTofind As String, highlightColor As Color, matchCase As Boolean, matchWholeWord As Boolean) As Boolean
Me.RichTextBox1.SelectAll()
Me.RichTextBox1.SelectionBackColor = Color.White
Dim startIndex As Integer = 0
Dim searchOption As RichTextBoxFinds = Nothing
If matchCase AndAlso matchWholeWord Then
searchOption = RichTextBoxFinds.MatchCase Or RichTextBoxFinds.WholeWord
ElseIf matchCase Then
searchOption = RichTextBoxFinds.MatchCase
ElseIf matchWholeWord Then
searchOption = RichTextBoxFinds.WholeWord
Else
searchOption = RichTextBoxFinds.None
End If
Dim found As Boolean = False
Dim index As Integer = -1
While (Me.FindIndex(Me.RichTextBox1.Find(stringTofind, startIndex, searchOption), index)) > -1
found = True
Me.RichTextBox1.SelectionBackColor = highlightColor
startIndex = index + 1
End While
Return found
End Function
Private Function FindIndex(value As Integer, ByRef index As Integer) As Integer
index = value
Return value
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim search As String = "vb4arab"
Dim found As Boolean = TryFindString(search, SystemColors.MenuHighlight, True, True)
If Not found Then
Dim errorString As String = String.Format("Can't find the word ""{0}"", try another word", search)
MessageBox.Show(errorString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
End Class

