How can i change the class and the functions inside to fit in any listBox items?
<p>I have this class wich im using to color text in the listBox in Form1:</p>

<pre><code>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&lt;string&gt; 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 &amp; 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));
                // Get the string to 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);

                // Get the place to draw it.
                size = e.Graphics.MeasureString(url, f);
                float positionX = size.Width;

                // Draw the 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();
          }
        }
    }
}
</code></pre>

<p>The problem is that in the function ColorListBox it's looking for specific string/item : "Local KeyWord"</p>

<p>But in Form1 the listBox might contain anything I mean it might contain any string I want this function to fit to work on any string in the listBox.</p>

<p>For example now in Form1 I did:</p>

<pre><code>                data.Add("System Fan Speed - ");
                listBox1.DataSource = data;
</code></pre>

<p>What I want to do is that the text on the right the names for example Gpu Temperature will be in Red then the string "-" will be black then the number the temperature it self will be Green.
I want that in this function I will be able to set the color for each part im choosing in the listBox items. </p>

<pre><code>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);
                }
            }
        }
</code></pre>
