منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
[سؤال] استفسار مهم - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : قسم لغة الفيجوال بيسك VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=182)
+--- قسم : قسم اسئلة VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=183)
+--- الموضوع : [سؤال] استفسار مهم (/showthread.php?tid=30455)



استفسار مهم - bakriano30@yahoo.com - 22-07-19

ريتش بوكس 1 
تيكست بوكس 1 
بوتن1 
الريتش بوكس فيه كلمه السلام عليكم 
محتاج اعمل بحث عن اي كلمه في الريتش بوكس من خلال التكست بوكس يعني لو كتبت السلام في التكست بوكس 
عند الضغط علي بوتن 1 يتغير لو خلفيه التكست بوكس الي اخضر


RE: استفسار مهم - سعود - 22-07-19

الشرح هنا وتمت التجربة بنجاح.


RE: استفسار مهم - bakriano30@yahoo.com - 22-07-19

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

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

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

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


RE: استفسار مهم - سعود - 22-07-19

موضوع سؤال زي موضوعنا والجواب تحت زي جوابي هذا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 



RE: استفسار مهم - bakriano30@yahoo.com - 22-07-19

(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 
كذالك الاخطاء تستمر من فضلك مثال بسيط اخ سعود  انا اسف لتعبك


RE: استفسار مهم - Basil Abdallah - 22-07-19

(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 



RE: استفسار مهم - bakriano30@yahoo.com - 22-07-19

(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 

بارك الله فيك هذا هو المطلوب


RE: استفسار مهم - سامي محمد - 22-07-19

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



RE: استفسار مهم - سعود - 22-07-19


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



RE: استفسار مهم - سامي محمد - 22-07-19

بهذه الطريقة

كود :
        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