منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : استفسار مهم
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
ريتش بوكس 1 
تيكست بوكس 1 
بوتن1 
الريتش بوكس فيه كلمه السلام عليكم 
محتاج اعمل بحث عن اي كلمه في الريتش بوكس من خلال التكست بوكس يعني لو كتبت السلام في التكست بوكس 
عند الضغط علي بوتن 1 يتغير لو خلفيه التكست بوكس الي اخضر
الشرح هنا وتمت التجربة بنجاح.
(22-07-19, 05:41 PM)سعود كتب : [ -> ]الشرح هنا وتمت التجربة بنجاح.

للاسف اطلعت عليه من قبل اخ سعود ولم افهم الكود اطلاقا حتي استعمله

(22-07-19, 05:41 PM)سعود كتب : [ -> ]الشرح هنا وتمت التجربة بنجاح.

للاسف اطلعت عليه من قبل اخ سعود ولم افهم الكود اطلاقا حتي استعمله
موضوع سؤال زي موضوعنا والجواب تحت زي جوابي هذاSmile
PHP كود :
Sub findTextAndHighlight(ByVal searchtext As StringByVal rtb As RichTextBox)
 
   Dim textEnd As Integer rtb.TextLength
    Dim index 
As Integer 0
    Dim fnt 
As Font = New Font(rtb.FontFontStyle.Bold)
 
   Dim lastIndex As Integer rtb.Text.LastIndexOf(searchtext)
 
   While (index lastIndex)
 
     rtb.Find(searchtextindextextEndRichTextBoxFinds.WholeWord)
 
     rtb.SelectionFont fnt
      rtb
.SelectionLength searchtext.Length
      rtb
.SelectionColor Color.Red
      rtb
.SelectionBackColor Color.Cyan
      index 
rtb.Text.IndexOf(searchtextindex) + 1
    End 
While
 
 End Sub

'============USAGE============

 Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
 '
this method with search for text "boy" in RichTextBox2change the textcolor to red and back color to cyan as indicated in the screenshot below 
 findTextAndHighlight
("boy"RichTextBox2  
 End Sub 
(22-07-19, 05:58 PM)سعود كتب : [ -> ]موضوع سؤال زي موضوعنا والجواب تحت زي جوابي هذاSmile
PHP كود :
Sub findTextAndHighlight(ByVal searchtext As StringByVal rtb As RichTextBox)
 
   Dim textEnd As Integer rtb.TextLength
    Dim index 
As Integer 0
    Dim fnt 
As Font = New Font(rtb.FontFontStyle.Bold)
 
   Dim lastIndex As Integer rtb.Text.LastIndexOf(searchtext)
 
   While (index lastIndex)
 
     rtb.Find(searchtextindextextEndRichTextBoxFinds.WholeWord)
 
     rtb.SelectionFont fnt
      rtb
.SelectionLength searchtext.Length
      rtb
.SelectionColor Color.Red
      rtb
.SelectionBackColor Color.Cyan
      index 
rtb.Text.IndexOf(searchtextindex) + 1
    End 
While
 
 End Sub

'============USAGE============

 Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
 '
this method with search for text "boy" in RichTextBox2change the textcolor to red and back color to cyan as indicated in the screenshot below 
 findTextAndHighlight
("boy"RichTextBox2  
 End Sub 
الجواب من ايدك يحلي اخ سعود

(22-07-19, 05:58 PM)سعود كتب : [ -> ]موضوع سؤال زي موضوعنا والجواب تحت زي جوابي هذاSmile
PHP كود :
Sub findTextAndHighlight(ByVal searchtext As StringByVal rtb As RichTextBox)
 
   Dim textEnd As Integer rtb.TextLength
    Dim index 
As Integer 0
    Dim fnt 
As Font = New Font(rtb.FontFontStyle.Bold)
 
   Dim lastIndex As Integer rtb.Text.LastIndexOf(searchtext)
 
   While (index lastIndex)
 
     rtb.Find(searchtextindextextEndRichTextBoxFinds.WholeWord)
 
     rtb.SelectionFont fnt
      rtb
.SelectionLength searchtext.Length
      rtb
.SelectionColor Color.Red
      rtb
.SelectionBackColor Color.Cyan
      index 
rtb.Text.IndexOf(searchtextindex) + 1
    End 
While
 
 End Sub

'============USAGE============

 Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
 '
this method with search for text "boy" in RichTextBox2change the textcolor to red and back color to cyan as indicated in the screenshot below 
 findTextAndHighlight
("boy"RichTextBox2  
 End Sub 
كذالك الاخطاء تستمر من فضلك مثال بسيط اخ سعود  انا اسف لتعبك
(22-07-19, 06:16 PM)bakriano30@yahoo.com كتب : [ -> ]
(22-07-19, 05:58 PM)سعود كتب : [ -> ]موضوع سؤال زي موضوعنا والجواب تحت زي جوابي هذاSmile
PHP كود :
Sub findTextAndHighlight(ByVal searchtext As StringByVal rtb As RichTextBox)
 
   Dim textEnd As Integer rtb.TextLength
    Dim index 
As Integer 0
    Dim fnt 
As Font = New Font(rtb.FontFontStyle.Bold)
 
   Dim lastIndex As Integer rtb.Text.LastIndexOf(searchtext)
 
   While (index lastIndex)
 
     rtb.Find(searchtextindextextEndRichTextBoxFinds.WholeWord)
 
     rtb.SelectionFont fnt
      rtb
.SelectionLength searchtext.Length
      rtb
.SelectionColor Color.Red
      rtb
.SelectionBackColor Color.Cyan
      index 
rtb.Text.IndexOf(searchtextindex) + 1
    End 
While
 
 End Sub

'============USAGE============

 Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
 '
this method with search for text "boy" in RichTextBox2change the textcolor to red and back color to cyan as indicated in the screenshot below 
 findTextAndHighlight
("boy"RichTextBox2  
 End Sub 
الجواب من ايدك يحلي اخ سعود

(22-07-19, 05:58 PM)سعود كتب : [ -> ]موضوع سؤال زي موضوعنا والجواب تحت زي جوابي هذاSmile
PHP كود :
Sub findTextAndHighlight(ByVal searchtext As StringByVal rtb As RichTextBox)
 
   Dim textEnd As Integer rtb.TextLength
    Dim index 
As Integer 0
    Dim fnt 
As Font = New Font(rtb.FontFontStyle.Bold)
 
   Dim lastIndex As Integer rtb.Text.LastIndexOf(searchtext)
 
   While (index lastIndex)
 
     rtb.Find(searchtextindextextEndRichTextBoxFinds.WholeWord)
 
     rtb.SelectionFont fnt
      rtb
.SelectionLength searchtext.Length
      rtb
.SelectionColor Color.Red
      rtb
.SelectionBackColor Color.Cyan
      index 
rtb.Text.IndexOf(searchtextindex) + 1
    End 
While
 
 End Sub

'============USAGE============

 Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
 '
this method with search for text "boy" in RichTextBox2change the textcolor to red and back color to cyan as indicated in the screenshot below 
 findTextAndHighlight
("boy"RichTextBox2  
 End Sub 
كذالك الاخطاء تستمر من فضلك مثال بسيط اخ سعود  انا اسف لتعبك

تفضل اخ كريم
PHP كود :
Dim txt As String
        txt 
RichTextBox1.Find(TextBox1.Text)
 
       RichTextBox1.SelectionBackColor Color.Red 
(22-07-19, 06:34 PM)Basil Abdallah كتب : [ -> ]
(22-07-19, 06:16 PM)bakriano30@yahoo.com كتب : [ -> ]
(22-07-19, 05:58 PM)سعود كتب : [ -> ]موضوع سؤال زي موضوعنا والجواب تحت زي جوابي هذاSmile
PHP كود :
Sub findTextAndHighlight(ByVal searchtext As StringByVal rtb As RichTextBox)
 
   Dim textEnd As Integer rtb.TextLength
    Dim index 
As Integer 0
    Dim fnt 
As Font = New Font(rtb.FontFontStyle.Bold)
 
   Dim lastIndex As Integer rtb.Text.LastIndexOf(searchtext)
 
   While (index lastIndex)
 
     rtb.Find(searchtextindextextEndRichTextBoxFinds.WholeWord)
 
     rtb.SelectionFont fnt
      rtb
.SelectionLength searchtext.Length
      rtb
.SelectionColor Color.Red
      rtb
.SelectionBackColor Color.Cyan
      index 
rtb.Text.IndexOf(searchtextindex) + 1
    End 
While
 
 End Sub

'============USAGE============

 Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
 '
this method with search for text "boy" in RichTextBox2change the textcolor to red and back color to cyan as indicated in the screenshot below 
 findTextAndHighlight
("boy"RichTextBox2  
 End Sub 
الجواب من ايدك يحلي اخ سعود

(22-07-19, 05:58 PM)سعود كتب : [ -> ]موضوع سؤال زي موضوعنا والجواب تحت زي جوابي هذاSmile
PHP كود :
Sub findTextAndHighlight(ByVal searchtext As StringByVal rtb As RichTextBox)
 
   Dim textEnd As Integer rtb.TextLength
    Dim index 
As Integer 0
    Dim fnt 
As Font = New Font(rtb.FontFontStyle.Bold)
 
   Dim lastIndex As Integer rtb.Text.LastIndexOf(searchtext)
 
   While (index lastIndex)
 
     rtb.Find(searchtextindextextEndRichTextBoxFinds.WholeWord)
 
     rtb.SelectionFont fnt
      rtb
.SelectionLength searchtext.Length
      rtb
.SelectionColor Color.Red
      rtb
.SelectionBackColor Color.Cyan
      index 
rtb.Text.IndexOf(searchtextindex) + 1
    End 
While
 
 End Sub

'============USAGE============

 Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
 '
this method with search for text "boy" in RichTextBox2change the textcolor to red and back color to cyan as indicated in the screenshot below 
 findTextAndHighlight
("boy"RichTextBox2  
 End Sub 
كذالك الاخطاء تستمر من فضلك مثال بسيط اخ سعود  انا اسف لتعبك

تفضل اخ كريم
PHP كود :
Dim txt As String
        txt 
RichTextBox1.Find(TextBox1.Text)
 
       RichTextBox1.SelectionBackColor Color.Red 

بارك الله فيك هذا هو المطلوب
بعد اذن جيمع الزملاء بارك الله فيهم ... اعتقد ان هذا الكود اسهم و اوضح ومختصر ايضا 
 
كود :
For Each x As Match In Regex.Matches(RichTextBox1.Text, TextBox1.Text)
            RichTextBox1.Select(x.Index, x.Length)
            RichTextBox1.SelectionBackColor = Color.Yellow
        Next
[صورة مرفقة: 999.png]

بارك الله فيكم جميعا وشكر لكم.
كيف ممكن نعدل بحيث لو انقصنا  من طول النص يتم الغاء ماكان مظلل بنتيجة البحث السابقة؟!
بهذه الطريقة

كود :
        RichTextBox1.SelectAll()
        RichTextBox1.SelectionBackColor = Color.White
        For Each x As Match In Regex.Matches(RichTextBox1.Text, TextBox1.Text)
            RichTextBox1.Select(x.Index, x.Length)
            RichTextBox1.SelectionBackColor = Color.Yellow
        Next