Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. private void listBox_DrawItem(object sender, DrawItemEventArgs e)
  2. {
  3. ListBox sendingListBox = (ListBox)sender;
  4.  
  5. CustomListBoxItem item = sendingListBox.Items[e.Index] as CustomListBoxItem; // Get the current item and cast it to MyListBoxItem
  6.  
  7. if (item != null)
  8. {
  9. e.Graphics.DrawString( // Draw the appropriate text in the ListBox
  10. item.Message, // The message linked to the item
  11. zone1ListBox.Font, // Take the font from the listbox
  12. new SolidBrush(item.ItemColor), // Set the color
  13. 0, // X pixel coordinate
  14. e.Index * zone1ListBox.ItemHeight // Y pixel coordinate. Multiply the index by the ItemHeight defined in the listbox.
  15. );
  16. }
  17. else
  18. {
  19. // The item isn't a MyListBoxItem, do something about it
  20. }
  21. }
  22.  
  23. public class DoubleBufferedListBox : ListBox {
  24. protected override CreateParams CreateParams {
  25. get {
  26. CreateParams cp = base.CreateParams;
  27. cp.ExStyle |= 0x02000000; // WS_EX_COMPOSITED
  28. return cp;
  29. }
  30. }
  31.  
  32. public DoubleBufferedListBox( ) {
  33. //DoubleBuffered = true;
  34. this.SetStyle(ControlStyles.DoubleBuffered, true);
  35. this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement