winforms - How to implement "Search Previous" in a "Find Keyword" Windows Form in C# -
i have log window in c# application. have implemented find keyword feature in form, searches matching text in richtextbox. want build feature search next , previous matches throughout richtextbox.
the code findnext
try { if (start_search_point < log_textbox.text.length && start_search_point != -1) { log_textbox.selectionbackcolor = highlight_all_color; log_textbox.find(search_keyword, start_search_point, richtextboxfinds.wholeword); log_textbox.selectionbackcolor = color.honeydew; if (start_search_point + search_keyword.length < log_textbox.text.length) start_search_point = log_textbox.text.indexof(search_keyword, start_search_point + search_keyword.length); else start_search_point = 0; } else { start_search_point = 0; } } catch (exception ex) { mdiparent.thismdiobj.txtlog.invoke(new action(() => mdiparent.thismdiobj.txtlog.appendtext(datetime.now.tostring() + " : " + ex.message + "=>" + ex.stacktrace.tostring() + environment.newline))); } can me findprevious part? cannot figure out logic one.
how creating matchcollection , work it?
matchcollection matches = new regex().matches(search_keyword); int currentindex = 0; and use currentindex elements collection-
if(currentindex > 0) --currentindex; // previous search result matches[currentindex]; example: 
Comments
Post a Comment