Click here to Skip to main content
15,896,526 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!

I try to write, code for search in rich text box like search in notepad but I have some of errors.
in my rich text box is text that they are response of web page. and maybe text changed.
how can I write a search text in richtextbox with c# that include ring ( for , while , ... ).

please help me.
Thank you!
Posted
Comments
StM0n 7-May-13 1:03am    
Sorry to ask, but is it ASP.Net or plain WinForms? And what errors do you have?
e.v.r 7-May-13 1:14am    
Thank you!
no, my program is application that work in network, and crawl in html code and find links. so i have request / response we page. now my response is in rich text box. now i want saerch any word for example ( html, ).
i want a search like search in notepad.

e.v.r 7-May-13 1:16am    
my code is here.

public partial class Form1 : Form
{
int start = 0;
int indexOfSearchText = 0;

public int FindText(string txtToSearch, int searchStart, int searchEnd)
{

if (searchStart > 0 && searchEnd > 0 && indexOfSearchText >= 0)
{
XSSResponceRichTextBox.Undo();
}

int retVal = -1;

if (searchStart >= 0 && indexOfSearchText >= 0)
{

if (searchEnd > searchStart || searchEnd == -1)
{

indexOfSearchText = XSSResponceRichTextBox.Find(txtToSearch, searchStart, searchEnd, RichTextBoxFinds.None);

if (indexOfSearchText != -1)
{
retVal = indexOfSearchText;
}

// if (indexOfSearchText == -1)
else
{
searchStart = 0;
indexOfSearchText = XSSResponceRichTextBox.Find(txtToSearch, searchStart, searchEnd, RichTextBoxFinds.None);
retVal = indexOfSearchText;
}

//if (indexOfSearchText == -1)
//{
// searchStart = 0;
// indexOfSearchText =XSSResponceRichTextBox.Find(txtToSearch, searchStart, searchEnd, System.Windows.Forms.RichTextBoxFinds.None);
// retVal = indexOfSearchText;
//}
}
}

return retVal;
}

public Form1()
{
InitializeComponent();
}

private void txtSearch_TextChanged(object sender, EventArgs e)
{
if (start != 0)
{
XSSResponceRichTextBox.Undo();
start = 0;
indexOfSearchText = 0;
}
}



private void txtSearch_KeyPress(object sender, KeyPressEventArgs e)
{
int startindex = 0;

if (e.KeyChar == ">
Shriniwas Shukla 7-May-13 13:32pm    
what error are you getting from this code?
e.v.r 8-May-13 3:07am    
My code can not run to my application.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900