void color_LostFocus(object sender, EventArgs e) { ColorEditorHost ce = sender as ColorEditorHost; if (ce != null) { Association a = ce.Tag as Association; a.Value = ce.SelectedColor; } }
public PropertyList(ArrayList properties) { this.ChildSpacing = new Size(2, 2); this.Margin = new Padding(0); this.Padding = new Padding(0); this.SuspendLayout(); for (int i = 0; i < properties.Count; i++) { Association a = properties[i] as Association; if (a == null) { string s = properties[i] as string; if (s.ToLower().Equals("separator")) { InputSeparator sep = new InputSeparator(); this.Items.Add(sep); } else if (s.ToLower().Equals("colbreak")) { this.Items[this.Items.Count - 1].Break = BreakType.Column; } else { InputGroupHeader gh = new InputGroupHeader(); gh.Text = s; gh.Height = unitHeight; gh.BackColor = Color.Transparent; this.Items.Add(gh); } } else if (a.Descriptor.PropertyType == Type.GetType("System.Boolean")) { InputCheckBox chk = new InputCheckBox(); chk.Height = unitHeight; chk.Checked = (bool)a.Value; chk.Tag = a; if (string.IsNullOrEmpty(a.LongName)) { chk.Text = a.Descriptor.Name + " "; } else { chk.Text = a.LongName + " "; } chk.CheckedChanged += new EventHandler(chk_CheckedChanged); this.Items.Add(chk); } else { InputLabel lab = new InputLabel(); lab.VerticalAlign = InputContentAlignment.Center; lab.Height = unitHeight; lab.Width = labelWidth; if (string.IsNullOrEmpty(a.LongName)) { lab.Text = a.Descriptor.Name; } else { lab.Text = a.LongName; } this.Items.Add(lab); if (a.Descriptor.PropertyType.IsEnum) { InputComboBox box = new InputComboBox(); box.Height = unitHeight; box.DropDownStyle = InputComboBoxStyle.DropDownList; BindingFlags flags = BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly; FieldInfo[] fields = a.Descriptor.PropertyType.GetFields(flags); box.Tag = a; box.Text = a.Value.ToString(); box.SelectedIndexChanged += new EventHandler(box_SelectedIndexChanged); for (int f = 0; f < fields.Length; f++) { var field = fields[f]; if (a.AllowedValues == null || a.AllowedValues.Contains(field.Name)) { InputOption ic = new InputOption(); ic.Text = field.GetValue(field).ToString(); ic.Tag = field; box.Items.Add(ic); } } this.Items.Add(box); } else if (a.Descriptor.PropertyType == Type.GetType("System.DateTime")) { InputDatePicker dp = new InputDatePicker(); dp.Height = unitHeight; dp.Value = (DateTime)a.Value; dp.Tag = a; dp.LostFocus += new EventHandler(date_LostFocus); this.Items.Add(dp); } else if (a.Descriptor.PropertyType == Type.GetType("System.TimeSpan")) { InputTimePicker tp = new InputTimePicker(); tp.Height = unitHeight; tp.Value = (TimeSpan)a.Value; tp.Tag = a; tp.LostFocus += new EventHandler(time_LostFocus); this.Items.Add(tp); } else if (a.Descriptor.PropertyType.ToString().Equals("System.Drawing.Color")) { ColorEditorHost ce = new ColorEditorHost(); ce.Height = unitHeight; ce.Width = 102; ce.SelectedColor = (System.Drawing.Color)a.Value; ce.Tag = a; ce.LostFocus += new EventHandler(color_LostFocus); this.Items.Add(ce); } else if (a.Descriptor.PropertyType == Type.GetType("System.Int32")) { InputNumericBox nb = new InputNumericBox(); nb.Height = unitHeight; nb.Width = 50; nb.Value = (int)a.Value; nb.Tag = a; nb.Maximum = 100000; nb.ValueChanged += new EventHandler(nb_ValueChanged); this.Items.Add(nb); } else if (a.Descriptor.PropertyType == Type.GetType("System.Int16")) { InputNumericBox nb = new InputNumericBox(); nb.Height = unitHeight; nb.Width = 50; nb.Value = (short)a.Value; nb.Tag = a; nb.Maximum = 100000; nb.ValueChanged += new EventHandler(nb_ValueChanged); this.Items.Add(nb); } else if (a.Descriptor.PropertyType == Type.GetType("System.Int64")) { InputNumericBox nb = new InputNumericBox(); nb.Value = (long)a.Value; nb.Tag = a; nb.Maximum = 100000; nb.Height = unitHeight; nb.Width = 50; nb.ValueChanged += new EventHandler(nb_ValueChanged); this.Items.Add(nb); } else if (a.Descriptor.PropertyType == Type.GetType("System.Single") || a.Descriptor.PropertyType == Type.GetType("System.Double")) { InputNumericBox nb = new InputNumericBox(); nb.Value = (decimal)Math.Floor((Single)a.Value); nb.Tag = a; nb.Maximum = 360; nb.Minimum = 0; nb.Height = unitHeight; nb.Width = 50; nb.ValueChanged += new EventHandler(nb_ValueChanged); this.Items.Add(nb); } else { InputTextBox txt = new InputTextBox(); txt.VerticalAlign = InputContentAlignment.Center; txt.Height = unitHeight; txt.Text = a.Value.ToString(); txt.Tag = a; txt.LostFocus += new EventHandler(txt_LostFocus); this.Items.Add(txt); } } } this.Dock = System.Windows.Forms.DockStyle.Fill; this.ResumeLayout(); }