c# - How to alternatively change BackColor of RTB text -
i've got requirement change text backcolor in rtb. rtb getting created in loop number of messages db.
implemented logic achieve feel logic simple.
able give idea implement same or mine fine?
code:
foreach (dataset.noterow note in _ds.note) { createnotes(note); } private void createnotes(string note) { //txt : rich text box dynamically created each note //test : selected text in 'note' int index = txt.text.toupper().indexof(test.toupper()); txt.select(index, test.length); txt.selectionfont = new font(txt.font.name, txt.font.size, txt.font.style^ fontstyle.bold); //x global variable initialised 1 if(x % 2 == 1) txt.selectionbackcolor = system.drawing.color.gray; x++; }
scenario :
if notes has 5 messages, alternative message should have gray backcolor.
try
private void createnotes(string note) { //txt : rich text box dynamically created each note //test : selected text in 'note' int index = txt.text.toupper().indexof(test.toupper()); txt.select(index, test.length); txt.selectionfont = new font(txt.font.name, txt.font.size, txt.font.style^ fontstyle.bold); random rnd = new random(); //x global variable initialised 1 if(x % 2 == 1) txt.selectionbackcolor = color.fromargb(rnd.next(255), rnd.next(255), rnd.next(255)); x++; }
Comments
Post a Comment