private void AddText(ObsProperty property, ObsData setting, List<Control> controls) { string name = property.Name; TextBox textbox = new TextBox { Width = 300, Text = setting.GetString(name) }; if (property.TextType == ObsTextType.Password) textbox.PasswordChar = '*'; else if (property.TextType == ObsTextType.Multiline) { textbox.Multiline = true; textbox.Height *= 3; } textbox.TextChanged += (sender, args) => { setting.SetString(name, textbox.Text); view.PropertyChanged(property); }; controls.Add(textbox); }
private void AddList(ObsProperty property, ObsData setting, List<Control> controls) { string name = property.Name; int index = 0; string[] names = property.GetListItemNames(); object[] values = property.GetListItemValues(); EventHandler selectedIndexChanged = null; ComboBox combobox = new ComboBox { Width = 300 }; combobox.Items.AddRange(names.ToArray()); //if (namelist.Length > 0) // combobox.SelectedIndex = 0; if (property.ListType == ObsComboType.List) combobox.DropDownStyle = ComboBoxStyle.DropDownList; switch (property.ListFormat) { case ObsComboFormat.Float: { index = Array.IndexOf(values, setting.GetDouble(name)); selectedIndexChanged = (sender, args) => { double value = (double)values.GetValue(combobox.SelectedIndex); setting.SetDouble(name, value); view.PropertyChanged(property); }; break; } case ObsComboFormat.Int: { var val = setting.GetInt(name); index = Array.IndexOf(values, setting.GetInt(name)); selectedIndexChanged = (sender, args) => { long value = (long)values[combobox.SelectedIndex]; setting.SetInt(name, (int)value); view.PropertyChanged(property); }; break; } case ObsComboFormat.String: { index = Array.IndexOf(values, setting.GetString(name)); selectedIndexChanged = (sender, args) => { string value = (string)values[combobox.SelectedIndex]; setting.SetString(name, value); view.PropertyChanged(property); }; break; } } if (index != -1) combobox.SelectedIndex = index; combobox.SelectedIndexChanged += selectedIndexChanged; if (index == -1 && names.Length > 0) combobox.SelectedIndex = 0; controls.Add(combobox); }
private void AddPath(ObsProperty property, ObsData setting, List<Control> controls) { string name = property.Name; TextBox textbox = new TextBox { Width = 300, Text = setting.GetString(name) }; Button button = new Button { Text = "Browse..." }; if (property.PathType == ObsPathType.File) { OpenFileDialog dialog = new OpenFileDialog { AutoUpgradeEnabled = true, Filter = property.PathFilter.ToString(), InitialDirectory = property.PathDefault, FilterIndex = 1 }; button.Click += (sender, args) => { if (dialog.ShowDialog(this) == DialogResult.OK) textbox.Text = dialog.FileName; }; } else if (property.PathType == ObsPathType.Directory) { FolderBrowserDialog dialog = new FolderBrowserDialog { SelectedPath = property.PathDefault }; button.Click += (sender, args) => { if (dialog.ShowDialog(this) == DialogResult.OK) textbox.Text = dialog.SelectedPath; }; } textbox.TextChanged += (sender, args) => { setting.SetString(name, textbox.Text); view.PropertyChanged(property); }; controls.Add(textbox); controls.Add(button); }
private void AddFont(ObsProperty property, ObsData setting, List<Control> controls) { string name = property.Name; Label label = new Label { Width = 300, Height = 60, AutoSize = false, BorderStyle = BorderStyle.Fixed3D, TextAlign = ContentAlignment.MiddleCenter }; Button button = new Button { Text = "Select..." }; using (ObsData fontData = new ObsData(setting.GetObject(name))) { string family = fontData.GetString("face"); //string style = fontData.GetString("style"); //not supported in Windows ObsFontFlags flags = (ObsFontFlags)fontData.GetInt("flags"); label.Font = new Font(family, 25F, (FontStyle)flags); ; label.Text = family; } button.Click += (sender, args) => { var fontDialog = new FontDialog(); using (ObsData fontData = new ObsData(setting.GetObject(name))) { float size = fontData.GetInt("size"); fontDialog.Font = new Font(label.Font.FontFamily, size, label.Font.Style); } if (fontDialog.ShowDialog() == DialogResult.OK) { var font = fontDialog.Font; using (ObsData fontData = new ObsData(setting.GetObject(name))) { fontData.SetString("face", font.Name.ToString()); fontData.SetString("style", ""); //not supported in Windows fontData.SetInt("size", (int)font.SizeInPoints); fontData.SetInt("flags", (int)font.Style); } view.PropertyChanged(property); font = new Font(font.Name, 25f, font.Style); label.Font = font; label.Text = font.Name; } }; controls.Add(label); controls.Add(button); }