So folgendes habe ich jetzt mal gemacht
eine Form StandardForm für:
Größe und Aussehen ohne Controls
ein Form StandardControls implements StandardForm für:
Größe und Aussehen der Controls
Mit der Funktion
C#-Code: |
public void copyProperties(Control copy, Control original)
{
List<string> properties = new List<string>();
properties.Add("Height");
properties.Add("Width");
properties.Add("DropDownStyle");
properties.Add("DropDownHeight");
properties.Add("DropDownWidth");
properties.Add("BackColor");
properties.Add("BackgroundImage");
properties.Add("BackgroundImageLayout");
properties.Add("UseVisualStyleBackColor");
properties.Add("Font");
properties.Add("ForeColor");
properties.Add("TextAlign");
properties.Add("Cursor");
properties.Add("Anchor");
properties.Add("Dock");
List<string> props = new List<string>();
Type type = original.GetType();
foreach (PropertyInfo prop in type.GetProperties())
{
if (prop.CanWrite && properties.Contains(prop.Name))
{
props.Add(prop.Name);
prop.SetValue(copy, prop.GetValue(original, null), null);
}
}
}
|
Jetzt kann ich im Programm selbst eigene StandardForms erstellen
Beispiel StandardBooking implements StandardForm
Mit der Funktion
C#-Code: |
private void formatControls()
{
Skinning.StandardControl stdControl = new Skinning.StandardControl();
stdControl.copyProperties(label1, stdControl.lblHeading);
stdControl.copyProperties(label2, stdControl.lblNormal);
stdControl.copyProperties(label3, stdControl.lblNormal);
stdControl.copyProperties(textBox1, stdControl.tbxNormal);
stdControl.copyProperties(textBox2, stdControl.tbxLarge);
stdControl.copyProperties(comboBox1, stdControl.cbxLarge);
stdControl.copyProperties(button1, stdControl.btnLarge);
}
|
Die eigentliche GUI wiederum greift dann auf die zugeschnittenen StandardForms über Vererbung zu
Beispiel CreateBooking implements StandardBooking
und ViewBooking implements StandardBooking
Diese Forms kann ich wiederum um weitere StandardControls erweitern:
Zum Beispiel einen weiteren Button, der dann wieder zur Laufzeit formatiert wird
C#-Code: |
stdControl.copyProperties(button1, stdControl.btnLarge);
|
Was haltet ihr davon?
Die AppConfig-Variante würde ich dann nutzen um User-Formatierungen zu speichern (Fenstergrößen, DataGrid-Sortierungen etc.)