DrawItemEventArgs.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System.Drawing;
  2. namespace System.Windows.Forms
  3. {
  4. public class DrawItemEventArgs : EventArgs
  5. {
  6. private Color backColor;
  7. private Color foreColor;
  8. private Font font;
  9. private readonly Graphics graphics;
  10. private readonly int index;
  11. private readonly Rectangle rect;
  12. private readonly DrawItemState state;
  13. public Color BackColor
  14. {
  15. get
  16. {
  17. if ((state & DrawItemState.Selected) == DrawItemState.Selected)
  18. {
  19. return System.Drawing.SystemColors.Highlight;
  20. }
  21. if ((state & DrawItemState.Disabled) == DrawItemState.Disabled)
  22. {
  23. return System.Drawing.SystemColors.Control;
  24. }
  25. if ((state & DrawItemState.HotLight) == DrawItemState.HotLight)
  26. {
  27. return System.Drawing.SystemColors.ControlLight;
  28. }
  29. return backColor;
  30. }
  31. }
  32. public Rectangle Bounds => rect;
  33. public Font Font => font;
  34. public Color ForeColor
  35. {
  36. get
  37. {
  38. if ((state & DrawItemState.Selected) == DrawItemState.Selected)
  39. {
  40. return System.Drawing.SystemColors.HighlightText;
  41. }
  42. if ((state & DrawItemState.Disabled) == DrawItemState.Disabled)
  43. {
  44. return System.Drawing.SystemColors.GrayText;
  45. }
  46. return foreColor;
  47. }
  48. }
  49. public Graphics Graphics => graphics;
  50. public int Index => index;
  51. public DrawItemState State => state;
  52. public DrawItemEventArgs(Graphics graphics, Font font, Rectangle rect, int index, DrawItemState state)
  53. {
  54. this.graphics = graphics;
  55. this.font = font;
  56. this.rect = rect;
  57. this.index = index;
  58. this.state = state;
  59. foreColor = System.Drawing.SystemColors.WindowText;
  60. backColor = System.Drawing.SystemColors.Window;
  61. }
  62. public DrawItemEventArgs(Graphics graphics, Font font, Rectangle rect, int index, DrawItemState state, Color foreColor, Color backColor)
  63. {
  64. this.graphics = graphics;
  65. this.font = font;
  66. this.rect = rect;
  67. this.index = index;
  68. this.state = state;
  69. this.foreColor = foreColor;
  70. this.backColor = backColor;
  71. }
  72. public virtual void DrawBackground()
  73. {
  74. Brush brush = new SolidBrush(BackColor);
  75. Graphics.FillRectangle(brush, rect);
  76. brush.Dispose();
  77. }
  78. public virtual void DrawFocusRectangle()
  79. {
  80. }
  81. }
  82. public delegate void DrawItemEventHandler(object sender, DrawItemEventArgs e);
  83. }