Click here to Skip to main content
15,914,820 members
Home / Discussions / C#
   

C#

 
GeneralRe: Delete From XML File Pin
PIEBALDconsult28-Aug-12 12:07
mvePIEBALDconsult28-Aug-12 12:07 
GeneralRe: Delete From XML File Pin
Kevin Marois28-Aug-12 12:21
professionalKevin Marois28-Aug-12 12:21 
AnswerRe: Delete From XML File Pin
PIEBALDconsult28-Aug-12 12:02
mvePIEBALDconsult28-Aug-12 12:02 
QuestionHow can I change this event handler? Pin
turbosupramk328-Aug-12 10:52
turbosupramk328-Aug-12 10:52 
AnswerRe: How can I change this event handler? Pin
Richard Andrew x6428-Aug-12 11:08
professionalRichard Andrew x6428-Aug-12 11:08 
GeneralRe: How can I change this event handler? Pin
turbosupramk328-Aug-12 14:32
turbosupramk328-Aug-12 14:32 
GeneralRe: How can I change this event handler? Pin
Richard Andrew x6428-Aug-12 15:20
professionalRichard Andrew x6428-Aug-12 15:20 
GeneralRe: How can I change this event handler? Pin
turbosupramk328-Aug-12 15:24
turbosupramk328-Aug-12 15:24 
GeneralRe: How can I change this event handler? Pin
Richard Andrew x6428-Aug-12 15:37
professionalRichard Andrew x6428-Aug-12 15:37 
GeneralRe: How can I change this event handler? Pin
turbosupramk328-Aug-12 15:52
turbosupramk328-Aug-12 15:52 
GeneralRe: How can I change this event handler? Pin
Richard Andrew x6428-Aug-12 15:58
professionalRichard Andrew x6428-Aug-12 15:58 
GeneralRe: How can I change this event handler? Pin
turbosupramk328-Aug-12 16:04
turbosupramk328-Aug-12 16:04 
GeneralRe: How can I change this event handler? Pin
Richard Andrew x6428-Aug-12 16:08
professionalRichard Andrew x6428-Aug-12 16:08 
GeneralRe: How can I change this event handler? Pin
turbosupramk328-Aug-12 16:15
turbosupramk328-Aug-12 16:15 
AnswerRe: How can I change this event handler? Pin
Richard Andrew x6428-Aug-12 16:28
professionalRichard Andrew x6428-Aug-12 16:28 
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 

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.