tbf/TBF/CustomStyle.cs

87 lines
3.2 KiB
C#

///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TBF
{
/// <summary>
/// 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).
/// </summary>
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];
}
/// <summary>
/// Set attributes of the set selected by 'set' parameter
/// </summary>
/// <param name="id">Attribute set ID</param>
/// <param name="dockStyle">Docking style</param>
/// <param name="backColor">Background color</param>
/// <param name="readOnly">true for read only (aka label)</param>
/// <param name="borderStyle">Border style</param>
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;
}
/// <summary>
/// Apply one of the attribute sets to a TextBox instance
/// </summary>
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];
}
/// <summary>
/// Apply one of the attribute sets to a AttachedTextBoxes text boxes
/// </summary>
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];
}
}
}
}