using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace TBF { /// /// This static class maintains a set of text box styles at one place, it is then sufficient /// to use the static method CustomStyle.Apply(id, textBox(es)) to apply this style to text box(es). /// public static class CustomStyle { const int setsCount = 20; /// Number of styles / attribute sets static DockStyle[] dockStyles; /// Docking style static System.Drawing.Color[] backColors; /// Background color static BorderStyle[] borderStyles; /// Border style static bool[] readOnly; /// Read only static System.Drawing.Font[] fonts; /// Font static CustomStyle() { dockStyles = new DockStyle[setsCount]; backColors = new System.Drawing.Color[setsCount]; borderStyles = new BorderStyle[setsCount]; readOnly = new bool[setsCount]; fonts = new System.Drawing.Font[setsCount]; } /// /// Set attributes of the set selected by 'set' parameter /// /// Attribute set ID /// Docking style /// Background color /// true for read only (aka label) /// Border style public static void Set(int id, DockStyle dockStyle, System.Drawing.Color backColor, BorderStyle borderStyle, bool readOnly, System.Drawing.Font font) { if (id < 0 || id >= setsCount) return; CustomStyle.dockStyles[id] = dockStyle; CustomStyle.backColors[id] = backColor; CustomStyle.borderStyles[id] = borderStyle; CustomStyle.readOnly[id] = readOnly; CustomStyle.fonts[id] = font; } /// /// Apply one of the attribute sets to a TextBox instance /// public static void Apply(int id, TextBox textBox) { if (id < 0 || id >= setsCount) return; textBox.Dock = dockStyles[id]; textBox.BackColor = backColors[id]; textBox.BorderStyle = borderStyles[id]; textBox.ReadOnly = readOnly[id]; textBox.Font = fonts[id]; } /// /// Apply one of the attribute sets to a AttachedTextBoxes text boxes /// public static void Apply(int id, AttachedTextBoxes textBoxes) { if (id < 0 || id >= setsCount) return; for (int i = 0; i < textBoxes.Count; i++) { textBoxes[i].Dock = dockStyles[id]; textBoxes[i].BackColor = backColors[id]; textBoxes[i].BorderStyle = borderStyles[id]; textBoxes[i].ReadOnly = readOnly[id]; textBoxes[i].Font = fonts[id]; } } } }