PDA

View Full Version : کمکی درxtbox حل مشکل



groupjahad
سه شنبه 29 مرداد 1387, 17:42 عصر
سلام

من می خوام یه سرچ روی richtextbox داشته باشم و کدی که زدم اینه
if (txtmessage.Text != "")
{
MessageBox.Show("Search Start");
for (; position_find != -1 && pos <= Lenght_Text ; )
{
position_find = richTextBox1.Find(txtmessage.Text, pos, Lenght_Text, System.Windows.Forms.RichTextBoxFinds.MatchCase );


txtfindresult.Text = position_find.ToString();
temp = position_find;
pos += temp;
MessageBox.Show(temp.ToString());

}
}
فقط یه مشکل دارم و اونم اینه که سرچ روی تمام عبارات انجام نمی شه یعنی اگر الف سرچ بشه باید 100 مورد نشون بده که فقط 10 مورد نشون میده
لطفاً کمک کنید

Blackk_lightt
سه شنبه 29 مرداد 1387, 19:43 عصر
سلام
از این کد استفاده کن جواب میده :


int pos=0;
int Lenght_Text = richTextBox1.Text.Length;
if (txtmessage.Text != "")
{
for (; pos != -1 && pos <= Lenght_Text; )
{
pos = richTextBox1.Text.IndexOf(txtmessage.Text, pos);
txtfindresult.Text = pos.ToString();
if (pos!=-1) pos += 1;
MessageBox.Show(pos.ToString());
}
}