I use ListBox to insert text like You add Michael in your database , You delete Michael , ...
listBox1.Items.Insert(0,"You add " + name + " in your database\n");
It is working fine. How can I set the color once black (for insertion) and once red (for removal)? I tried with this:
public class MyListBoxItem { public MyListBoxItem(Color c, string m) { ItemColor = c; Message = m; } public Color ItemColor { get; set; } public string Message { get; set; } } private void listBox1_DrawItem(object sender, DrawItemEventArgs e) { MyListBoxItem item = listBox1.Items[e.Index] as MyListBoxItem;
And when pasting:
listBox1.Items.Insert(0, new MyListBoxItem(Color.Black, "You add " + name + " in your database\n")); listBox1.Items.Insert(0, new MyListBoxItem(Color.Red, "You delete " + name + "\n"));
This code works, but when I insert some elements, scrolling does not work correctly - the text does not appear. What am I doing wrong? Or is this another way to do this?
source share