Click here to Skip to main content
15,886,199 members
Home / Discussions / C#
   

C#

 
GeneralRe: How can I change this event handler? Pin
turbosupramk328-Aug-12 16:47
turbosupramk328-Aug-12 16:47 
AnswerRe: How can I change this event handler? Pin
Richard Andrew x6428-Aug-12 16:55
professionalRichard Andrew x6428-Aug-12 16:55 
GeneralRe: How can I change this event handler? Pin
turbosupramk329-Aug-12 4:29
turbosupramk329-Aug-12 4:29 
AnswerRe: How can I change this event handler? Pin
BobJanova28-Aug-12 23:14
BobJanova28-Aug-12 23:14 
GeneralRe: How can I change this event handler? Pin
turbosupramk329-Aug-12 4:28
turbosupramk329-Aug-12 4:28 
GeneralRe: How can I change this event handler? Pin
BobJanova29-Aug-12 4:51
BobJanova29-Aug-12 4:51 
GeneralRe: How can I change this event handler? Pin
turbosupramk329-Aug-12 5:05
turbosupramk329-Aug-12 5:05 
GeneralRe: How can I change this event handler? Pin
turbosupramk329-Aug-12 5:50
turbosupramk329-Aug-12 5:50 
Thank you for the help Bob.

Here is what I ended up doing

And here is how it looks, I'm going to try and make the colors softer so the black text is easier to read, but I'm happy with it besides that.
http://img690.imageshack.us/img690/8922/lineeditor2.png[^]


C#
public class MyListBoxItem
{
    public MyListBoxItem(Color t, string m, Color c)
    {
        BackgroundColor = c;
        Message = m;
        TextColor = t;
    }
    public Color BackgroundColor { get; set; }
    public string Message { get; set; }
    public Color TextColor { get; set; }
}


private void testFunction()
{
    try
    {
        lbxOutput.DrawMode = DrawMode.OwnerDrawFixed;
        lbxOutput.DrawItem += new DrawItemEventHandler(listBox_DrawItem);

        lbxOutput.Items.Add(new MyListBoxItem(Color.Black, "Validated data successfully", Color.Green));
        lbxOutput.Items.Add(new MyListBoxItem(Color.Black, "Failed to validate data", Color.Red));
        lbxOutput.Items.Add(new MyListBoxItem(Color.Black, "Validated data successfully", Color.Green));
        lbxOutput.Items.Add(new MyListBoxItem(Color.Black, "Failed to validate data", Color.Red));
        lbxOutput.Items.Add(new MyListBoxItem(Color.Black, "Validated data successfully", Color.Green));
        lbxOutput.Items.Add(new MyListBoxItem(Color.Black, "Failed to validate data", Color.Red));
        lbxOutput.Items.Add(new MyListBoxItem(Color.Black, "Validated data successfully", Color.Green));
        lbxOutput.Items.Add(new MyListBoxItem(Color.Black, "Failed to validate data", Color.Red));
        lbxOutput.Items.Add(new MyListBoxItem(Color.Black, "Validated data successfully", Color.Green));
        lbxOutput.Items.Add(new MyListBoxItem(Color.Black, "Failed to validate data", Color.Red));
        lbxOutput.Items.Add(new MyListBoxItem(Color.Black, "Validated data successfully", Color.Green));
        lbxOutput.Items.Add(new MyListBoxItem(Color.Black, "Failed to validate data", Color.Red));
        lbxOutput.Items.Add(new MyListBoxItem(Color.Black, "Validated data successfully", Color.Green));
        lbxOutput.Items.Add(new MyListBoxItem(Color.Black, "Failed to validate data", Color.Red));

   }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message + " " + ex.StackTrace + " " + ex.Source);
    }
}

private void listBox_DrawItem(object sender, DrawItemEventArgs e)
{
    MyListBoxItem item = lbxOutput.Items[e.Index] as MyListBoxItem; // Get the current item and cast it to MyListBoxItem
    Graphics g = e.Graphics;
    if (item != null)
    {
        g.FillRectangle(new SolidBrush(item.BackgroundColor), e.Bounds); // Draw this first, so you can draw over it with the text
        e.Graphics.DrawString( // Draw the appropriate text in the ListBox
            item.Message, // The message linked to the item
            lbxOutput.Font, // Take the font from the listbox
            //new SolidBrush(item.ItemColor), // Set the color
            new SolidBrush(item.TextColor), // Set the color
            0, // X pixel coordinate
            e.Index * lbxOutput.ItemHeight // Y pixel coordinate.  Multiply the index by the ItemHeight defined in the listbox.
        );
        //e.DrawBackground();
        //Graphics g = e.Graphics;

    }
    else
    {
        // The item isn't a MyListBoxItem, do something about it
    }
}

GeneralRe: How can I change this event handler? Pin
BobJanova29-Aug-12 6:25
BobJanova29-Aug-12 6:25 
GeneralRe: How can I change this event handler? Pin
turbosupramk329-Aug-12 6:48
turbosupramk329-Aug-12 6:48 
GeneralRe: How can I change this event handler? Pin
turbosupramk330-Aug-12 6:37
turbosupramk330-Aug-12 6:37 
QuestionSpeechSynthesizer is too fast Pin
Jassim Rahma28-Aug-12 10:37
Jassim Rahma28-Aug-12 10:37 
AnswerRe: SpeechSynthesizer is too fast Pin
Ravi Bhavnani29-Aug-12 7:31
professionalRavi Bhavnani29-Aug-12 7:31 
QuestionSpecific Fill size Pin
Jassim Rahma28-Aug-12 10:02
Jassim Rahma28-Aug-12 10:02 
AnswerRe: Specific Fill size Pin
Eddy Vluggen28-Aug-12 10:33
professionalEddy Vluggen28-Aug-12 10:33 
AnswerRe: Specific Fill size Pin
BobJanova28-Aug-12 23:15
BobJanova28-Aug-12 23:15 
QuestionUsing UserControls Pin
WebMaster28-Aug-12 9:04
WebMaster28-Aug-12 9:04 
AnswerRe: Using UserControls Pin
Ian Shlasko28-Aug-12 9:26
Ian Shlasko28-Aug-12 9:26 
GeneralRe: Using UserControls Pin
WebMaster28-Aug-12 9:30
WebMaster28-Aug-12 9:30 
GeneralRe: Using UserControls Pin
Ian Shlasko28-Aug-12 9:44
Ian Shlasko28-Aug-12 9:44 
GeneralRe: Using UserControls Pin
WebMaster28-Aug-12 9:46
WebMaster28-Aug-12 9:46 
GeneralRe: Using UserControls Pin
Ian Shlasko28-Aug-12 9:50
Ian Shlasko28-Aug-12 9:50 
GeneralRe: Using UserControls Pin
WebMaster28-Aug-12 9:54
WebMaster28-Aug-12 9:54 
GeneralRe: Using UserControls Pin
Ian Shlasko28-Aug-12 9:59
Ian Shlasko28-Aug-12 9:59 
GeneralRe: Using UserControls Pin
WebMaster28-Aug-12 10:08
WebMaster28-Aug-12 10:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.