#if NETFX || NETCORE using System; using System.Collections.Generic; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Apewer.Surface { /// internal class BlockList : ListBox { private List _color = new List(); /// public BlockList() { Font = FormsUtility.DefaultFont; BorderStyle = BorderStyle.None; DrawMode = DrawMode.OwnerDrawVariable; SelectionMode = SelectionMode.One; MeasureItem += event_measureitem; DrawItem += event_drawitem; } /// private void event_drawitem(object sender, DrawItemEventArgs e) { if (_color.Count > 0) { RectangleF vrf = new RectangleF(8, e.Bounds.Top + 4, e.Bounds.Width - 16, 16); Brush vb = new SolidBrush(getcolor(e.Index)); string vs = Items[e.Index].ToString(); e.DrawBackground(); e.DrawFocusRectangle(); e.Graphics.DrawString(vs, e.Font, vb, vrf); } } /// private void event_measureitem(object sender, MeasureItemEventArgs e) { e.ItemHeight = 25; } /// private Color getcolor(int argIndex) { if (argIndex >= _color.Count) return ForeColor; return _color[argIndex]; } /// public void append(string argText) { write(argText, ForeColor); } /// public void write(string argText) { write(argText, ForeColor); } /// public void black(string argText) { write(argText, FormsUtility.Black); } /// public void green(string argText) { write(argText, FormsUtility.Green); } /// public void red(string argText) { write(argText, FormsUtility.Red); } /// public void gray(string argText) { write(argText, FormsUtility.GraceLocked); } /// public void error(string argText) { red(argText); } /// public void write(string argText, Color argColor) { var vtext = string.IsNullOrEmpty(argText) ? "" : argText.Trim(); while (_color.Count < Items.Count) { _color.Add(ForeColor); } while (_color.Count > Items.Count) { _color.RemoveAt(_color.Count - 1); } _color.Add((argColor == null) ? FormsUtility.Black : argColor); Items.Add(vtext); } /// public void selectlast() { if (Items.Count > 0) SelectedIndex = Items.Count - 1; } } } #endif