 
 
RichTextBox ta Arama
Bu makalemizde richTextBox nesnemiz içinde yazılı olan string te arama yaptıracağız. Aşağıdaki şekilleri inceleyin. Formunuza 1 adet textBox, button ve richTextBox ekleyin...Bahadirsa

Şekil 1

Şekil 2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
          private void Form1_Load(object sender, EventArgs e)
        {
        btnAra.Font = new Font("Verdana", 10, FontStyle.Regular);
        richTextBox1.Font = new Font("Verdana", 10, FontStyle.Regular);
        txtAra.Font = new Font("Verdana", 10, FontStyle.Regular);
        richTextBox1.Text = "Merhaba Bahadirsa. Bu örneğimizde kelime aramaya örnek vereceğiz. Öncelikle aranacak kelimeyi yukarıdaki textbox a giriniz." ;
        txtAra.Text = "Aranacak kelimeyi buraya gir...";
        this.Text = "Arama Uygulaması...Bahadirsa";
        this.MaximizeBox = false;
       
        }
        private void btnAra_Click(object sender, EventArgs e)
        {
          int r;
         
        r = richTextBox1.Text.IndexOf(txtAra.Text);
            if (r > 0)
            {
              
                richTextBox1.Select(r, txtAra.Text.Length);
                richTextBox1.SelectionBackColor = Color.Black;
                richTextBox1.SelectionFont = new Font("Verdana", 12, FontStyle.Bold);
                richTextBox1.SelectionColor = Color.Yellow;
MessageBox.Show("Aranılan kelime, " + (r+1) + " . karakterde bulundu.");
             }
            else
            {
MessageBox.Show("Üzgünüz. Aranılan kelime bulunamadı");
            }
        }
        
        private void txtAra_TextClick(object sender, EventArgs e)
        {
        
        richTextBox1.SelectionBackColor = Color.White;
        richTextBox1.SelectionColor = Color.Black;
        richTextBox1.SelectionFont = new Font("Verdana", 10, FontStyle.Regular);
        
        }
               
      
    }
}
//Bir sonraki makalede görüşmek üzere...Bahadirsa