C# Tutorial - How to Search and Highlight Text in a RichTextBox | FoxLearn

Поделиться
HTML-код
  • Опубликовано: 18 ноя 2024

Комментарии • 27

  • @naqeebcomputers2153
    @naqeebcomputers2153 7 лет назад

    I Watch and Downloaded all Your Videos... Very Very excellent & helpful for me > Thanks

  • @victormckeighan7613
    @victormckeighan7613 7 лет назад +4

    Very good, thanks!! Just one comment --- at end of while loop, the assignment of startIndex should be '=', not '+='. Took me a little while to find out why all instances of my searched word were not being found.

    • @_Ali_zz
      @_Ali_zz 2 года назад

      thank you, I also encountered such a problem and thanks to you it was solved❤❤

  • @Verses01
    @Verses01 7 лет назад

    Thank you sooo much!! This helped my immensely!!!

  • @rabihg1845
    @rabihg1845 8 лет назад

    thank u....do u know a method ,class or library to insert a dynamic sizable table to richtextbox c#?

    • @foxlearn
      @foxlearn  7 лет назад +1

      No, I think you can copy table, then paste to richtextbox. first you need to copy table then add to resource, see video how to add equation to richtextbox, i think similar the way. thanks

  • @Zhrine1337
    @Zhrine1337 8 лет назад +1

    Great videos dude, keep it up :)

    • @foxlearn
      @foxlearn  8 лет назад

      Thank you so much :)

  • @muhammadshaoorsiddique7681
    @muhammadshaoorsiddique7681 7 лет назад

    hello...thanku its amazing....kindly help me that who we (count) these highlighted words .....

  • @faisalyousfani5450
    @faisalyousfani5450 8 лет назад

    hey nice work keep it up .. but in my case i have my own searching method .. now i wanted to highlight the searched words .. can you help me out .. ???

    • @foxlearn
      @foxlearn  8 лет назад

      Ok. Let's me research. thanks

    • @heartbreaker-tv3348
      @heartbreaker-tv3348 5 лет назад

      public static void Find(RichTextBox rtb, String word, Color color)
      {
      rtb.SelectionStart = 0;
      rtb.SelectionLength = rtb.TextLength;
      rtb.SelectionColor = Color.Black;
      if (word == "")
      {
      return;
      }
      int s_start = rtb.SelectionStart, startIndex = 0, index;
      while ((index = rtb.Text.IndexOf(word, startIndex)) != -1)
      {
      rtb.Select(index, word.Length);
      rtb.SelectionColor = color;
      startIndex = index + word.Length;
      }
      }
      private void button1_Click(object sender, EventArgs e)
      {
      Find(richtext, textBox1.Text, Color.Blue);
      }
      That highlights it :)

  • @nebi0s
    @nebi0s 5 лет назад +1

    Well.. I know this is an old Video but that code has an error and it will not work as intended. at the end of the while loop, the startIndex variable increments with the last found word index value plus its length, with the intention of continuing the search from the last match. The problem is that incrementing the value will skip many hits. The value should be incremented but changed: It should be "startIndex = wordStartIndex + word.Length;"
    cheers

    • @foxlearn
      @foxlearn  5 лет назад

      Thank you for your suggestion. Let me check again

  • @ameerabdaljabar
    @ameerabdaljabar 8 лет назад

    nice
    i have surce code have some error
    cam i connact for u to help me ?

    • @foxlearn
      @foxlearn  8 лет назад

      Yes, You can contact me via email. You can find my email in the about tab. Thanks

  • @muhammadfahriansyah3795
    @muhammadfahriansyah3795 8 лет назад +1

    yess.. my problem solved, after watch this video

    • @foxlearn
      @foxlearn  8 лет назад +1

      That's great. Thank you so much ^_^

  • @heartbreaker-tv3348
    @heartbreaker-tv3348 5 лет назад

    Hi! I was wondering: How would I accomplish this from a different form? Say, if I were to press Ctrl+F, then Form2 should come up, with the find, find next, etc.
    I have the code (It works!) except that if I enter the richtextbox after find a word, the text is all blue. Here is my source:
    public static void Find(RichTextBox rtb, String word, Color color)
    {
    rtb.SelectionStart = 0;
    rtb.SelectionLength = rtb.TextLength;
    rtb.SelectionColor = Color.Black;
    if (word == "")
    {
    return;
    }
    int s_start = rtb.SelectionStart, startIndex = 0, index;
    while ((index = rtb.Text.IndexOf(word, startIndex)) != -1)
    {
    rtb.Select(index, word.Length);
    rtb.SelectionColor = color;
    startIndex = index + word.Length;
    }
    }
    private void button1_Click(object sender, EventArgs e)
    {
    Find(richtext, textBox1.Text, Color.Blue);
    }
    That is in Form2.cs I already know how to connect Form1 to Form2, I just need help fixing the selectioncolor after they find some text.

    • @foxlearn
      @foxlearn  5 лет назад

      OK. Thank you for your suggestion. I'll update soon

  • @alshentec2286
    @alshentec2286 2 года назад

    Sorry but 3:14 I can't find the Find method is word!!

  • @klausdorr2306
    @klausdorr2306 Год назад

    the program is wrong. startindex += must be startindex =

  • @black_s0ck
    @black_s0ck 7 лет назад

    Isn't there an easier way to do this, without any indexof and shit, cause it is pretty complicated for only the back color

  • @ameerabdaljabar
    @ameerabdaljabar 8 лет назад +1

    nice
    i have surce code have some error
    cam i connact for u to help me ?

    • @foxlearn
      @foxlearn  8 лет назад

      Hi, What error are you getting ? Thanks