You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.1 KiB

  1. #if NETFX || NETCORE
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Text;
  6. using System.Windows.Forms;
  7. namespace Apewer.Surface
  8. {
  9. /// <summary></summary>
  10. internal class BlockList : ListBox
  11. {
  12. private List<Color> _color = new List<Color>();
  13. /// <summary></summary>
  14. public BlockList()
  15. {
  16. Font = FormsUtility.DefaultFont;
  17. BorderStyle = BorderStyle.None;
  18. DrawMode = DrawMode.OwnerDrawVariable;
  19. SelectionMode = SelectionMode.One;
  20. MeasureItem += event_measureitem;
  21. DrawItem += event_drawitem;
  22. }
  23. /// <summary></summary>
  24. private void event_drawitem(object sender, DrawItemEventArgs e)
  25. {
  26. if (_color.Count > 0)
  27. {
  28. RectangleF vrf = new RectangleF(8, e.Bounds.Top + 4, e.Bounds.Width - 16, 16);
  29. Brush vb = new SolidBrush(getcolor(e.Index));
  30. string vs = Items[e.Index].ToString();
  31. e.DrawBackground();
  32. e.DrawFocusRectangle();
  33. e.Graphics.DrawString(vs, e.Font, vb, vrf);
  34. }
  35. }
  36. /// <summary></summary>
  37. private void event_measureitem(object sender, MeasureItemEventArgs e)
  38. {
  39. e.ItemHeight = 25;
  40. }
  41. /// <summary></summary>
  42. private Color getcolor(int argIndex)
  43. {
  44. if (argIndex >= _color.Count) return ForeColor;
  45. return _color[argIndex];
  46. }
  47. /// <summary></summary>
  48. public void append(string argText)
  49. {
  50. write(argText, ForeColor);
  51. }
  52. /// <summary></summary>
  53. public void write(string argText)
  54. {
  55. write(argText, ForeColor);
  56. }
  57. /// <summary></summary>
  58. public void black(string argText)
  59. {
  60. write(argText, FormsUtility.Black);
  61. }
  62. /// <summary></summary>
  63. public void green(string argText)
  64. {
  65. write(argText, FormsUtility.Green);
  66. }
  67. /// <summary></summary>
  68. public void red(string argText)
  69. {
  70. write(argText, FormsUtility.Red);
  71. }
  72. /// <summary></summary>
  73. public void gray(string argText)
  74. {
  75. write(argText, FormsUtility.GraceLocked);
  76. }
  77. /// <summary></summary>
  78. public void error(string argText)
  79. {
  80. red(argText);
  81. }
  82. /// <summary></summary>
  83. public void write(string argText, Color argColor)
  84. {
  85. var vtext = string.IsNullOrEmpty(argText) ? "" : argText.Trim();
  86. while (_color.Count < Items.Count)
  87. {
  88. _color.Add(ForeColor);
  89. }
  90. while (_color.Count > Items.Count)
  91. {
  92. _color.RemoveAt(_color.Count - 1);
  93. }
  94. _color.Add((argColor == null) ? FormsUtility.Black : argColor);
  95. Items.Add(vtext);
  96. }
  97. /// <summary></summary>
  98. public void selectlast()
  99. {
  100. if (Items.Count > 0) SelectedIndex = Items.Count - 1;
  101. }
  102. }
  103. }
  104. #endif