using System.Collections; using System.Drawing; using System.Drawing.Drawing2D; namespace System.Windows.Forms { internal static class ResPool { private static Hashtable pens = new(); private static Hashtable brushes = new(); private static Hashtable fonts = new(); public static Pen GetPen(Color color) { return GetPen(color, 1, DashStyle.Solid); } public static Pen GetPen(Color color, float width) { return GetPen(color, width, DashStyle.Solid); } public static Pen GetPen(Color color, float width, DashStyle style) { int hash = color.GetHashCode() ^ width.GetHashCode() ^ style.GetHashCode(); Pen result = pens[hash] as Pen; if (result == null) { result = new Pen(color, width); result.DashStyle = style; pens[hash] = result; } return result; } public static SolidBrush GetSolidBrush(Color color) { int hash = color.GetHashCode(); SolidBrush result = brushes[hash] as SolidBrush; if (result == null) { result = new SolidBrush(color); brushes[hash] = result; } return result; } public static Font GetFont(FontFamily name, float size, Drawing.FontStyle style) { int hash = name.GetHashCode() ^ size.GetHashCode() ^ style.GetHashCode(); Font result = fonts[hash] as Font; if (result == null) { result = new Font(name, size, style); fonts[hash] = result; } return result; } } }