/// <summary> /// Insert the option label /// </summary> private HtmlLabel InsertLabelForItem(Config.ConfigAttribute attr, ref int yPos) { var lbl = new HtmlLabel { AutoSizeHeightOnly = true, BackColor = Color.Transparent, Location = new Point(30, yPos), Size = new Size(270, 10), IsSelectionEnabled = false, Text = attr.Label }; yPos += lbl.Height + 10; return(lbl); }
/// <summary> /// Insert the correct input for the option /// </summary> private Control InsertInputForItem(FieldInfo property, Config.ConfigAttribute attr, ref int yPos) { // Build control type Control retVal; if (property.FieldType == typeof(bool)) { // for bool var tg = new YamuiButtonToggle { Location = new Point(320, yPos), Size = new Size(40, 16), Text = null, Checked = (bool)property.GetValue(Config.Instance) }; tg.ButtonPressed += (sender, args) => OnFieldModified(); retVal = tg; } else if (property.FieldType.IsEnum) { // for enum var dataSource = new List <string>(); foreach (var name in Enum.GetNames(property.FieldType)) { var attribute = Attribute.GetCustomAttribute(property.FieldType.GetField(name), typeof(DescriptionAttribute), true) as DescriptionAttribute; dataSource.Add(attribute != null ? attribute.Description : name); } dataSource = dataSource.Select(s => s.Replace("_", " ").Trim()).ToNonNullList(); var cb = new YamuiComboBox { Location = new Point(320, yPos), Size = new Size(Math.Min(300, dataSource.Select(s => TextRenderer.MeasureText(s, FontManager.GetStandardFont()).Width).Max() + 25), 20), DataSource = dataSource, }; cb.SelectedIndex = Enum.GetNames(property.FieldType).IndexOf(property.GetValue(Config.Instance).ConvertToStr()); cb.SelectedIndexChangedByUser += box => OnFieldModified(); retVal = cb; } else { // for everything else var tb = new YamuiTextBox { Location = new Point(320, yPos), Size = new Size(300, 20), Text = property.GetValue(Config.Instance).ConvertToStr(), Multiline = false, CausesValidation = true }; tb.Enter += (s, e) => tb.SelectAll(); if (property.FieldType == typeof(char)) { tb.KeyPress += (s, e) => { e.Handled = !char.IsControl(e.KeyChar) && tb.TextLength > 0; } } ; else { tb.KeyPress += (s, e) => { e.Handled = Utilities.IsInvalidKey(e.KeyChar, property.FieldType); } }; tb.Validating += ValidateTextBox; tb.Validated += (s, e) => errorProvider.SetError(tb, ""); tb.TextChanged += (sender, args) => OnFieldModified(); errorProvider.SetIconPadding(tb, -18); errorProvider.Icon = ImageResources.IcoError; retVal = tb; } var undoButton = new YamuiButtonImage { BackGrndImage = ImageResources.UndoUserAction, Size = new Size(20, 20), Location = new Point(retVal.Left + retVal.Width + 5, yPos), Tag = retVal, TabStop = false }; undoButton.ButtonPressed += OnUndoButton; scrollPanel.ContentPanel.Controls.Add(undoButton); tooltip.SetToolTip(undoButton, "Click to <b>reset this field</b> to its default value"); // add tooltip on the control if (!string.IsNullOrEmpty(attr.Tooltip)) { var rangeAttr = (RangeAttribute)property.GetCustomAttributes(typeof(RangeAttribute), false).FirstOrDefault(); tooltip.SetToolTip(retVal, "<b>" + attr.Label + ":</b><br><br>" + attr.Tooltip + (rangeAttr != null ? "<br><b><i>" + "Min value = " + rangeAttr.Minimum + "<br>Max value = " + rangeAttr.Maximum + "</i></b>" : "")); } // Set standard props retVal.Name = "option_" + property.Name; retVal.Tag = property; return(retVal); }