c# - Comment and Uncomment Code -


im working on contextmenu shows on rightclick using mousedown event , 2of list contextmenu comment , uncomment code:

private void commentmenuitemclick(object sender, eventargs e)     {         rtb.selectedtext = "//" + rtb.selectedtext;         lb.hide();     }      private void uncommentmenuitemclick(object sender, eventargs e)     {         rtb.selectedtext = rtb.selectedtext.replace("//", "");         lb.hide();         rtb.selectioncolor = color.black;     } 

but comment when select , theres diff rows of text (selectall) output was:

enter image description here

but should like:

enter image description here

how can that? add // before diff rows of text? suggestion? uncomment code enough? or theres more better code that? pls lot!

--- edit

void parse()     {         string inputlanguage = "\n";          // foreach line in input,         // identify key words , format them when adding rich text box.         regex r = new regex("\\n");         string[] lines = r.split(inputlanguage);         foreach (string l in lines)         {             parseline(l);         }     } 

your problem adding '//' start of text.

you need parse selected text new line char , prepend '//' start of each line.

string builder described here, it's in system.text

something this:

private void commentmenuitemclick(object sender, eventargs e) {     stringbuilder sw = new stringbuilder();      string line;     stringreader rdr = new stringreader(rtb.selectedtext);     line = rdr.readline();     while(line != null)     {             sw.appendline(string.isnullorwhitespace(line) ? "//" : "" + line);             line= rdr.readline();     }     rtb.selectedtext = sw.tostring();     lb.hide(); } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -