c# - How can i change the class and the functions inside to fit in any listBox items? -


i have class wich im using color text in listbox in form1:

using system; using system.collections.generic; using system.linq; using system.text; using system.drawing; using system.windows.forms;  namespace gatherlinks {     class colortext     {           public static void texts(richtextbox box, string text, color color)         {             box.selectionstart = box.textlength;             box.selectionlength = 0;              box.selectioncolor = color;             box.appendtext(text);             box.selectioncolor = box.forecolor;         }          public static void colorlistbox(list<string> data, drawitemeventargs e)         {             int keywords = 0;             string keyword = null;             string url = data[e.index].substring(0, 5);             if (data[e.index].contains("local keyword:"))             {                 keywords = data[e.index].indexof("local keyword:");                 keyword = data[e.index].substring(keywords, 14);             }             else             {                 keywords = data[e.index].indexof("localy keyword:");                 keyword = data[e.index].substring(keywords, 15);             }              using (font f = new font(fontfamily.genericsansserif, 8, fontstyle.regular))             {                 if ((e.state & drawitemstate.selected) == drawitemstate.selected)                     e.graphics.fillrectangle(brushes.lightblue, e.bounds);                 else                 {                     using (solidbrush sb = new solidbrush(systemcolors.window))                         e.graphics.fillrectangle(sb, e.bounds);                 }                  sizef size = e.graphics.measurestring(url, f);                 using (solidbrush sb = new solidbrush(color.red))                 {                     e.graphics.drawstring(url, f, sb, new pointf(e.bounds.x, e.bounds.y));                     string tomeasure = data[e.index].substring(0, keywords - 1);                     float startpos = e.graphics.measurestring(tomeasure, f).width;                     e.graphics.drawstring(keyword, f, sb, new pointf(e.bounds.x + (int)startpos, e.bounds.y));                 }                 // string token = data[e.index].substring(url.length, data[e.index].lastindexof(" --- ") - (url.length));                 // e.graphics.drawstring(token, f, brushes.black, new pointf(e.bounds.x + size.width, e.bounds.y));                 // string print in black.                 int first = url.length;                 int last = data[e.index].lastindexof(" --- ") + 5; //(5 = length of " --- ").                 int length = last - first;                 string token = data[e.index].substring(first, length);                  // place draw it.                 size = e.graphics.measurestring(url, f);                 float positionx = size.width;                  // draw string.                 e.graphics.drawstring(token, f, brushes.black, new pointf(positionx, e.bounds.y));                  //size = e.graphics.measurestring(url + token, f);                 //size = e.graphics.measurestring("url:" + token, f);                 //e.graphics.drawstring(data[e.index].substring(data[e.index].indexof(token) + token.length, data[e.index].lastindexof(": ") - token.length - data[e.index].indexof(token) + 1), f, brushes.black, new pointf(size.width, e.bounds.y));                  token = data[e.index].substring(data[e.index].lastindexof(": ") + 2);                 size = e.graphics.measurestring(data[e.index].substring(0, data[e.index].lastindexof(token)), f);                 using (solidbrush sb = new solidbrush(color.green))                     e.graphics.drawstring(token, f, sb, new pointf(e.bounds.x + size.width + 4, e.bounds.y));                  e.drawfocusrectangle();           }         }     } } 

the problem in function colorlistbox it's looking specific string/item : "local keyword"

but in form1 listbox might contain mean might contain string want function fit work on string in listbox.

for example in form1 did:

                data.add("system fan speed - ");                 listbox1.datasource = data; 

what want text on right names example gpu temperature in red string "-" black number temperature self green. want in function able set color each part im choosing in listbox items.

private void listbox1_drawitem(object sender, drawitemeventargs e)         {             if (e.index == -1)             {             }             else             {                 string url = data[e.index].substring(0, 5);                  using (font f = new font(fontfamily.genericsansserif, 8, fontstyle.regular))                 {                     colortext.colorlistbox(data, e);                 }             }         } 


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -