public override void ViewDidLoad() { base.ViewDidLoad(); // Sets the preview to the image record passed in ImageView.Image = ImageRecord.FullImage; // sets up font picker and picks a random font model = new PickerViewModel(this); FontPicker.Model = model; var randomFont = (new Random()).Next() % UIFont.FamilyNames.Length; FontPicker.Select(randomFont, 0, false); // Sets up the label with random font ImageLabel.Font = UIFont.FromName(UIFont.FamilyNames [randomFont], 24); // sets delegates so enter dimsisses keyboard TagField.ShouldReturn = TextFieldShouldReturn; HiddenText.ShouldReturn = TextFieldShouldReturn; // typing into the hiddent text field automatically updates the label on the image HiddenText.EditingChanged += OnDidEditField; // start editing the text field as soon as the view is done loading HiddenText.BecomeFirstResponder(); }
public FontPickerSection() { var layout = new DynamicLayout(); layout.DefaultPadding = new Padding(10); layout.DefaultSpacing = new Size(4, 4); layout.BeginVertical(); layout.BeginHorizontal(); layout.Add(new Label { Text = "Default: ", VerticalAlignment = VerticalAlignment.Center }); var fontpicker1 = new FontPicker(); LogEvents(fontpicker1); layout.Add(fontpicker1, true, false); layout.EndHorizontal(); layout.BeginHorizontal(); layout.Add(new Label { Text = "Initial Value: ", VerticalAlignment = VerticalAlignment.Center }); var fontpicker2 = new FontPicker(new Font(SystemFont.Default)); LogEvents(fontpicker2); layout.Add(fontpicker2, true, false); layout.EndHorizontal(); layout.Add(null, false, true); layout.EndVertical(); Content = layout; }
void LogEvents(FontPicker control) { control.ValueChanged += delegate { Log.Write(control, "FontChanged, Font: " + control.Value); }; }
private void Font_Click(object sender, RoutedEventArgs e) { FontPicker picker = new FontPicker(); picker.Text = textlist[labelIndex]; picker.ShowDialog(); }
private void BracketFont_Click(object sender, RoutedEventArgs e) { FontPicker picker = new FontPicker(); picker.Text = ((Bracket)GraphicController.Selected.Graphic).ExampleLabel; picker.BracketRedraw = true; picker.ShowDialog(); }
Control WrapLabel() { const string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; var label = new Label { Text = text }; var wrapDropDown = new EnumDropDown <WrapMode>(); wrapDropDown.SelectedValueBinding.Bind(label, l => l.Wrap); var textAlignmentDropDown = new EnumDropDown <TextAlignment>(); textAlignmentDropDown.SelectedValueBinding.Bind(label, l => l.TextAlignment); var verticalAlignmentDropDown = new EnumDropDown <VerticalAlignment>(); verticalAlignmentDropDown.SelectedValueBinding.Bind(label, l => l.VerticalAlignment); var testVerticalAlignment = new CheckBox { Text = "Test VerticalAlignment" }; testVerticalAlignment.CheckedChanged += (sender, e) => label.Size = new Size(-1, testVerticalAlignment.Checked == true ? 200 : -1); testVerticalAlignment.CheckedBinding.Bind(verticalAlignmentDropDown, c => c.Enabled, DualBindingMode.OneWayToSource); var fontSelector = new FontPicker(); fontSelector.Bind(c => c.Value, label, l => l.Font); Func <Control> spacer = () => new Panel { BackgroundColor = Colors.DarkGray, Size = new Size(10, 10) }; return(new StackLayout { HorizontalContentAlignment = HorizontalAlignment.Stretch, Items = { TableLayout.Horizontal(5, null, "Wrap:", wrapDropDown, "Font:", fontSelector, null), TableLayout.Horizontal(5, null, testVerticalAlignment, verticalAlignmentDropDown, "TextAlignment:", textAlignmentDropDown, null), spacer(), new TableLayout( new TableRow( spacer(), new TableCell(label, true), spacer() ) ), spacer() } }); }
Control WrapLabel() { var label = new Label { Text = Utility.LoremText }; var wrapDropDown = new EnumDropDown <WrapMode>(); wrapDropDown.SelectedValueBinding.Bind(label, l => l.Wrap); var textAlignmentDropDown = new EnumDropDown <TextAlignment>(); textAlignmentDropDown.SelectedValueBinding.Bind(label, l => l.TextAlignment); var verticalAlignmentDropDown = new EnumDropDown <VerticalAlignment>(); verticalAlignmentDropDown.SelectedValueBinding.Bind(label, l => l.VerticalAlignment); var testVerticalAlignment = new CheckBox { Text = "Test VerticalAlignment" }; testVerticalAlignment.CheckedChanged += (sender, e) => label.Size = new Size(-1, testVerticalAlignment.Checked == true ? 200 : -1); testVerticalAlignment.CheckedBinding.Bind(verticalAlignmentDropDown, c => c.Enabled, DualBindingMode.OneWayToSource); var fontSelector = new FontPicker(); fontSelector.Bind(c => c.Value, label, l => l.Font); Func <Control> spacer = () => new Panel { BackgroundColor = Colors.DarkGray, Size = new Size(10, 10) }; return(new StackLayout { HorizontalContentAlignment = HorizontalAlignment.Stretch, Items = { TableLayout.Horizontal(5, null, "Wrap:", wrapDropDown, "Font:", fontSelector, null), TableLayout.Horizontal(5, null, testVerticalAlignment, verticalAlignmentDropDown, "TextAlignment:", textAlignmentDropDown, null), spacer(), new TableLayout( new TableRow( spacer(), new TableCell(label, true), spacer() ) ), spacer() } }); }
private void defaultFontToolStripMenuItem_Click(object sender, EventArgs e) { FontPicker.Font = current_preset.default_font; FontPicker.ShowApply = false; if (DialogResult.OK == FontPicker.ShowDialog()) { current_preset.default_font = FontPicker.Font; Saver.save_preset_default_font(current_preset.name, current_preset.default_font); foreach (CustomButton button in Panel.Controls.OfType <CustomButton>()) { button.Font = FontPicker.Font; button.property_watcher = true; } } }
private void Fontbutton_Click(object sender, EventArgs e) { FontPicker.Font = currentButton.Font; FontPicker.ShowApply = true; var a = currentButton.Font; if (DialogResult.OK == FontPicker.ShowDialog()) { currentButton.Font = FontPicker.Font; currentButton.property_watcher = true; } else { currentButton.Font = a; } }
public FormattedTextSection() { var font = SystemFonts.Default(); var color = Colors.White; var formattedText = new FormattedText { Text = Utility.LoremText, MaximumSize = new SizeF(200, 100), Wrap = FormattedTextWrapMode.Word, Trimming = FormattedTextTrimming.CharacterEllipsis, ForegroundBrush = Brushes.White, //ForegroundBrush = new LinearGradientBrush(Colors.White, Colors.Blue, new PointF(0, 0), new PointF(200, 200)), Font = font }; var control = new Drawable { Size = new Size(400, 500), BackgroundColor = Colors.Black }; control.Paint += (sender, e) => { var g = e.Graphics; var location = new Point(10, 10); g.DrawText(font, color, location, "Single Line Text That Will Not Wrap 漢字"); location.Y += 40; var rect = new RectangleF(location, new SizeF(300, 20)); g.DrawRectangle(Colors.Blue, rect); g.DrawText(font, new SolidBrush(color), rect, "Should Be Right Aligned", FormattedTextWrapMode.None, FormattedTextAlignment.Right, FormattedTextTrimming.None); location.Y += 40; g.DrawRectangle(Colors.Blue, new RectangleF(location, formattedText.MaximumSize)); var size = formattedText.Measure(); g.DrawText(formattedText, location); g.DrawRectangle(Colors.Silver, new RectangleF(location, size)); }; var wrapMode = new EnumDropDown <FormattedTextWrapMode>(); wrapMode.SelectedValueBinding.Bind(formattedText, f => f.Wrap); wrapMode.SelectedValueChanged += (sender, e) => control.Invalidate(); var trimming = new EnumDropDown <FormattedTextTrimming>(); trimming.SelectedValueBinding.Bind(formattedText, f => f.Trimming); trimming.SelectedValueChanged += (sender, e) => control.Invalidate(); var alignment = new EnumDropDown <FormattedTextAlignment>(); alignment.SelectedValueBinding.Bind(formattedText, f => f.Alignment); alignment.SelectedValueChanged += (sender, e) => control.Invalidate(); var fontSelection = new FontPicker(); fontSelection.ValueBinding.Bind(formattedText, f => f.Font); fontSelection.ValueChanged += (sender, e) => control.Invalidate(); var maxSizeEntry = new SizeFEntry(); maxSizeEntry.ValueBinding.Bind(formattedText, f => f.MaximumSize); maxSizeEntry.ValueChanged += (sender, e) => control.Invalidate(); var layout = new DynamicLayout(); layout.BeginCentered(); layout.AddSeparateRow("Wrap:", wrapMode, null); layout.AddSeparateRow("Trimming:", trimming, null); layout.AddSeparateRow("Alignment:", alignment, null); layout.AddSeparateRow("Font:", fontSelection, null); layout.AddSeparateRow("MaximumSize:", maxSizeEntry, null); layout.EndCentered(); layout.Add(control); Content = layout; }
protected override Control CreateOptions() { var foregroundPicker = new ColorPicker { AllowAlpha = true }; foregroundPicker.ValueChanged += (sender, e) => { foreach (var update in foregroundUpdates) { update(foregroundPicker.Value); } }; var backgroundPicker = new ColorPicker { AllowAlpha = true }; // alpha not supported for all controls backgroundPicker.ValueChanged += (sender, e) => { foreach (var update in backgroundUpdates) { update(backgroundPicker.Value); } }; var formColorPicker = new ColorPicker { Value = BackgroundColor, AllowAlpha = true }; formColorPicker.ValueChanged += (sender, e) => BackgroundColor = formColorPicker.Value; var fontPicker = new FontPicker { Value = SystemFonts.Default() }; fontPicker.ValueChanged += (sender, e) => { var font = fontPicker.Value; foreach (var update in fontUpdates) { update(font); } }; return(new StackLayout { Orientation = Orientation.Horizontal, Spacing = 5, Items = { null, new Label { Text = "Text",VerticalAlignment = VerticalAlignment.Center }, foregroundPicker, new Label { Text = "Background",VerticalAlignment = VerticalAlignment.Center }, backgroundPicker, new Label { Text = "Form",VerticalAlignment = VerticalAlignment.Center }, formColorPicker, fontPicker, null } }); }
void Initialize() { s.CreateAndAddLabelRow(container, "General"); s.CreateAndAddStringEditorRow(container, "Simulation Name", flowsheet.FlowsheetOptions.SimulationName, (sender, e) => flowsheet.FlowsheetOptions.SimulationName = sender.Text); s.CreateAndAddDescriptionRow(container, "The simulation name will be used for report identification and file name during saving."); var avunits = flowsheet.AvailableSystemsOfUnits.Select((x) => x.Name).ToList(); s.CreateAndAddLabelRow(container, "System of Units"); Button btnEdit = null; DropDown uselector = null; uselector = s.CreateAndAddDropDownRow(container, "System of Units", avunits, avunits.IndexOf(flowsheet.FlowsheetOptions.SelectedUnitSystem.Name), (sender, e) => { flowsheet.FlowsheetOptions.SelectedUnitSystem = flowsheet.AvailableSystemsOfUnits.Where((x) => x.Name == avunits[sender.SelectedIndex]).FirstOrDefault(); btnEdit.Enabled = !new string[] { "SI", "CGS", "ENG" }.Contains(uselector.SelectedValue.ToString()); }); s.CreateAndAddDescriptionRow(container, "Select the System of Units to be used on this simulation"); btnEdit = s.CreateAndAddLabelAndButtonRow(container, "Edit System of Units", "Edit Selected", null, (sender, e) => { var editcontainer = new Editors.UnitSetEditorView((DWSIM.SharedClasses.SystemsOfUnits.Units)flowsheet.FlowsheetOptions.SelectedUnitSystem); var form = s.GetDefaultEditorForm("Edit System of Units", 400, 600, editcontainer); form.Closed += (sender2, e2) => { container.RemoveAll(); container.Clear(); Initialize(); container.Create(); }; form.Show(); }); s.CreateAndAddLabelAndButtonRow(container, "Create New System of Units", "Create New", null, (sender, e) => { var newsystem = new DWSIM.SharedClasses.SystemsOfUnits.SI { Name = "NewUnitSet" }; flowsheet.AvailableSystemsOfUnits.Add(newsystem); flowsheet.FlowsheetOptions.SelectedUnitSystem = newsystem; var editcontainer = new Editors.UnitSetEditorView(newsystem); var form = s.GetDefaultEditorForm("Create New System of Units", 400, 600, editcontainer); form.Closed += (sender2, e2) => { container.RemoveAll(); container.Clear(); Initialize(); container.Create(); }; form.Show(); }); btnEdit.Enabled = !new string[] { "SI", "CGS", "ENG" }.Contains(uselector.SelectedValue.ToString()); var nformats = new[] { "F", "G", "G2", "G4", "G6", "G8", "G10", "N", "N2", "N4", "N6", "R", "E", "E1", "E2", "E3", "E4", "E6" }; s.CreateAndAddLabelRow(container, "Mass and Energy Balances"); s.CreateAndAddDropDownRow(container, "Flowsheet object mass balance check", new List <string>() { "Ignore", "Show Warning", "Throw Exception" }, (int)flowsheet.FlowsheetOptions.MassBalanceCheck, (sender, e) => { flowsheet.FlowsheetOptions.MassBalanceCheck = (DWSIM.Interfaces.Enums.WarningType)sender.SelectedIndex; }); s.CreateAndAddTextBoxRow(container, "G", "Mass balance relative tolerance", flowsheet.FlowsheetOptions.MassBalanceRelativeTolerance, (sender, e) => { if (sender.Text.IsValidDouble()) { flowsheet.FlowsheetOptions.MassBalanceRelativeTolerance = sender.Text.ToDoubleFromCurrent(); } }); s.CreateAndAddDropDownRow(container, "Flowsheet object energy balance check", new List <string>() { "Ignore", "Show Warning", "Throw Exception" }, (int)flowsheet.FlowsheetOptions.EnergyBalanceCheck, (sender, e) => { flowsheet.FlowsheetOptions.EnergyBalanceCheck = (DWSIM.Interfaces.Enums.WarningType)sender.SelectedIndex; }); s.CreateAndAddTextBoxRow(container, "G", "Energy balance relative tolerance", flowsheet.FlowsheetOptions.EnergyBalanceRelativeTolerance, (sender, e) => { if (sender.Text.IsValidDouble()) { flowsheet.FlowsheetOptions.EnergyBalanceRelativeTolerance = sender.Text.ToDoubleFromCurrent(); } }); s.CreateAndAddLabelRow(container, "Number Formats"); s.CreateAndAddDropDownRow(container, "General", nformats.ToList(), nformats.ToList().IndexOf(flowsheet.FlowsheetOptions.NumberFormat), (sender, e) => { flowsheet.FlowsheetOptions.NumberFormat = sender.SelectedValue.ToString(); }); s.CreateAndAddDescriptionRow(container, "Select the formatting scheme for general numbers."); s.CreateAndAddDropDownRow(container, "Compound Amounts", nformats.ToList(), nformats.ToList().IndexOf(flowsheet.FlowsheetOptions.FractionNumberFormat), (sender, e) => { flowsheet.FlowsheetOptions.FractionNumberFormat = sender.SelectedValue.ToString(); }); s.CreateAndAddDescriptionRow(container, "Select the formatting scheme for compound amounts in Material Stream reports."); s.CreateAndAddLabelRow(container, "Floating Tables and Anchored Property Lists"); s.CreateAndAddCheckBoxRow(container, "Display Floating Tables", flowsheet.FlowsheetOptions.DisplayFloatingPropertyTables, (sender, e) => { flowsheet.FlowsheetOptions.DisplayFloatingPropertyTables = sender.Checked.GetValueOrDefault(); var surface = (DWSIM.Drawing.SkiaSharp.GraphicsSurface)(flowsheet.GetSurface()); surface.DrawFloatingTable = flowsheet.FlowsheetOptions.DisplayFloatingPropertyTables; }); s.CreateAndAddCheckBoxRow(container, "Display Compound Amount Floating Tables for Material Streams", flowsheet.FlowsheetOptions.DisplayFloatingTableCompoundAmounts, (sender, e) => { flowsheet.Options.DisplayFloatingTableCompoundAmounts = sender.Checked.GetValueOrDefault(); }); s.CreateAndAddDropDownRow(container, "Compound Amount Default Basis", new List <string>() { "Molar Fractions", "Mass Fractions", "Volumetric Fractions", "Molar Flows", "Mass Flows", "Volumetric Flows" }, (int)flowsheet.FlowsheetOptions.DefaultFloatingTableCompoundAmountBasis, (sender, e) => { flowsheet.FlowsheetOptions.DefaultFloatingTableCompoundAmountBasis = (DWSIM.Interfaces.Enums.CompositionBasis)sender.SelectedIndex; }); s.CreateAndAddCheckBoxRow(container, "Display Anchored Property Lists", flowsheet.FlowsheetOptions.DisplayCornerPropertyList, (sender, e) => { flowsheet.FlowsheetOptions.DisplayCornerPropertyList = sender.Checked.GetValueOrDefault(); var surface = (DWSIM.Drawing.SkiaSharp.GraphicsSurface)(flowsheet.GetSurface()); surface.DrawPropertyList = flowsheet.FlowsheetOptions.DisplayCornerPropertyList; }); s.CreateAndAddLabelRow(container, "Anchored Property List Settings"); var fonts = Eto.Drawing.Fonts.AvailableFontFamilies.Select((x) => x.Name.ToLower()).ToList(); if (!fonts.Contains(flowsheet.FlowsheetOptions.DisplayCornerPropertyListFontName.ToLower())) { flowsheet.FlowsheetOptions.DisplayCornerPropertyListFontName = Eto.Drawing.FontFamilies.MonospaceFamilyName; } var fp = new FontPicker(new Eto.Drawing.Font(flowsheet.FlowsheetOptions.DisplayCornerPropertyListFontName, flowsheet.FlowsheetOptions.DisplayCornerPropertyListFontSize)); fp.ValueChanged += (sender, e) => { if (fp.Value != null) { flowsheet.FlowsheetOptions.DisplayCornerPropertyListFontName = fp.Value.FamilyName; flowsheet.FlowsheetOptions.DisplayCornerPropertyListFontSize = (int)fp.Value.Size; } }; s.CreateAndAddLabelAndControlRow(container, "Font Name and Size", fp); var colors = new SkiaSharp.SKColors(); var fontcolors = colors.GetType().GetFields().Select((x) => x.Name).ToList(); s.CreateAndAddDropDownRow(container, "Font Color", fontcolors, fontcolors.IndexOf(flowsheet.FlowsheetOptions.DisplayCornerPropertyListFontColor), (sender, e) => { flowsheet.FlowsheetOptions.DisplayCornerPropertyListFontColor = fontcolors[sender.SelectedIndex]; }); var paddings = new List <string>() { "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }; s.CreateAndAddDropDownRow(container, "Line Padding", paddings, paddings.IndexOf(flowsheet.FlowsheetOptions.DisplayCornerPropertyListPadding.ToString()), (sender, e) => { flowsheet.FlowsheetOptions.DisplayCornerPropertyListPadding = int.Parse(paddings[sender.SelectedIndex]); }); }
public RichTextAreaSection() { var richText = new RichTextArea(); richText.Size = new Size(-1, 300); //richText.Font = new Font("Arial", 10); var buffer = richText.Buffer; /**/ richText.Text = LastText; var range = new Range <int>(6, 10); buffer.SetFont(range, Fonts.Cursive(20, FontStyle.Bold, FontDecoration.Underline)); buffer.SetForeground(range, Colors.Blue); buffer.SetBackground(range, Colors.Yellow); buffer.SetBold(new Range <int>(11, 16), true); buffer.SetItalic(new Range <int>(18, 20), true); buffer.SetUnderline(new Range <int>(22, 25), true); buffer.SetStrikethrough(new Range <int>(28, 38), true); richText.CaretIndex = LastText.Length - 1; /**/ richText.SelectionChanged += (sender, e) => { UpdateBindings(BindingUpdateMode.Destination); Log.Write(sender, "SelectionChanged: {0}", richText.Selection); }; var boldButton = new CheckBox { Text = "Bold" }; boldButton.CheckedBinding.Bind(richText, r => r.SelectionBold); boldButton.CheckedChanged += (sender, e) => { richText.Focus(); UpdateBindings(BindingUpdateMode.Destination); }; var italicButton = new CheckBox { Text = "Italic" }; italicButton.CheckedBinding.Bind(richText, r => r.SelectionItalic); italicButton.CheckedChanged += (sender, e) => { richText.Focus(); UpdateBindings(BindingUpdateMode.Destination); }; var underlineButton = new CheckBox { Text = "Underline" }; underlineButton.CheckedBinding.Bind(richText, r => r.SelectionUnderline); underlineButton.CheckedChanged += (sender, e) => richText.Focus(); var strikethroughButton = new CheckBox { Text = "Strikethrough" }; strikethroughButton.CheckedBinding.Bind(richText, r => r.SelectionStrikethrough); strikethroughButton.CheckedChanged += (sender, e) => richText.Focus(); var backgroundButton = new ColorPicker { }; backgroundButton.ValueBinding.Bind(() => richText.SelectionBackground, val => richText.SelectionBackground = val, h => Binding.AddPropertyEvent(richText, r => r.SelectionBackground, h), h => Binding.RemovePropertyEvent(richText, h)); backgroundButton.ValueChanged += (sender, e) => richText.Focus(); var foregroundButton = new ColorPicker { }; foregroundButton.ValueBinding.Bind(richText, r => r.SelectionForeground); foregroundButton.ValueChanged += (sender, e) => richText.Focus(); var fontButton = new FontPicker(); fontButton.ValueBinding.Bind(richText, r => r.SelectionFont); fontButton.ValueChanged += (sender, e) => { richText.Focus(); UpdateBindings(BindingUpdateMode.Destination); }; var typefaceDropDown = new DropDown(); typefaceDropDown.ItemKeyBinding = Binding.Property((FontTypeface f) => f.Name); typefaceDropDown.DataStore = richText.SelectionFamily.Typefaces; var tyepfaceBinding = typefaceDropDown.SelectedValueBinding.Bind(richText, r => r.SelectionTypeface); typefaceDropDown.SelectedValueChanged += (sender, e) => { richText.Focus(); UpdateBindings(BindingUpdateMode.Destination); }; var familyDropDown = new DropDown(); familyDropDown.ItemTextBinding = Binding.Property((FontFamily f) => f.LocalizedName); familyDropDown.DataStore = Fonts.AvailableFontFamilies.OrderBy(r => r.LocalizedName); familyDropDown.SelectedValueBinding.Bind(richText, r => r.SelectionFamily); familyDropDown.SelectedValueChanged += (sender, e) => { var family = familyDropDown.SelectedValue as FontFamily; //tyepfaceBinding.Mode = DualBindingMode.Manual; typefaceDropDown.DataStore = family?.Typefaces; //tyepfaceBinding.Mode = DualBindingMode.TwoWay; richText.Focus(); UpdateBindings(BindingUpdateMode.Destination); }; var formatEnum = new EnumDropDown <RichTextAreaFormat>(); formatEnum.SelectedValue = RichTextAreaFormat.Rtf; var loadButton = new Button { Text = "Load" }; loadButton.Enabled = buffer.SupportedFormats.Contains(formatEnum.SelectedValue); loadButton.Click += (sender, e) => buffer.Load(new MemoryStream(Encoding.UTF8.GetBytes(formatEnum.SelectedValue == RichTextAreaFormat.Rtf ? RtfString : LastText)), formatEnum.SelectedValue); var loadFileButton = new Button { Text = "Load File..." }; loadFileButton.Enabled = buffer.SupportedFormats.Contains(formatEnum.SelectedValue); loadFileButton.Click += (sender, e) => { var dlg = new OpenFileDialog { Filters = { new FileFilter("RTF", ".rtf"), new FileFilter("TXT", "txt") } }; if (dlg.ShowDialog(this) == DialogResult.Ok) { var useRtf = string.Equals(Path.GetExtension(dlg.FileName), ".rtf", StringComparison.OrdinalIgnoreCase); var fs = File.OpenRead(dlg.FileName); buffer.Load(fs, useRtf ? RichTextAreaFormat.Rtf : RichTextAreaFormat.PlainText); } }; var saveButton = new Button { Text = "Save" }; saveButton.Enabled = buffer.SupportedFormats.Contains(formatEnum.SelectedValue); saveButton.Click += (sender, e) => { var stream = new MemoryStream(); buffer.Save(stream, formatEnum.SelectedValue); stream.Position = 0; if (formatEnum.SelectedValue == RichTextAreaFormat.Rtf) { RtfString = Encoding.UTF8.GetString(stream.ToArray()); } else { LastText = Encoding.UTF8.GetString(stream.ToArray()); } Log.Write(richText, "Saved {0}:\n{1}", formatEnum.SelectedValue, new StreamReader(stream).ReadToEnd()); }; formatEnum.SelectedValueChanged += (sender, e) => saveButton.Enabled = loadButton.Enabled = buffer.SupportedFormats.Contains(formatEnum.SelectedValue); var clearButton = new Button { Text = "Clear" }; clearButton.Click += (sender, e) => buffer.Clear(); var formatting1 = new StackLayout { Orientation = Orientation.Horizontal, Spacing = 5, Items = { null, boldButton, italicButton, underlineButton, strikethroughButton, null } }; var formatting2 = new StackLayout { Orientation = Orientation.Horizontal, Spacing = 5, Items = { null, new Label { Text = "Foreground", VerticalAlignment = VerticalAlignment.Center }, TableLayout.AutoSized(foregroundButton,centered: true), new Label { Text = "Background", VerticalAlignment = VerticalAlignment.Center }, TableLayout.AutoSized(backgroundButton,centered: true), null } }; var formatting3 = new StackLayout { Orientation = Orientation.Horizontal, Spacing = 5, Items = { null, fontButton, familyDropDown, typefaceDropDown, null } }; var buttons = new StackLayout { Orientation = Orientation.Horizontal, Spacing = 5, Items = { null, formatEnum, loadButton, saveButton, loadFileButton, clearButton, null } }; Content = new StackLayout { Padding = new Padding(10), Spacing = 5, HorizontalContentAlignment = HorizontalAlignment.Stretch, Items = { buttons, TextAreaSection.TextAreaOptions(richText), TextAreaSection.TextAreaOptions2(richText), TextAreaSection.TextAreaOptions3(richText), formatting1, formatting2, formatting3, new StackLayoutItem(richText, expand: true) } }; }
public DynamicSettingsControl() { InitializeComponent(); evaluator = new DataTable(); DefaultEditors.Add(typeof(bool), "checkbox"); DefaultEditors.Add(typeof(string), "textbox"); DefaultEditors.Add(typeof(Color), "colorpicker"); DefaultEditors.Add(typeof(Font), "fontpicker"); #region Default Control Builders // Checkbox Builder EditorBuilders.Add("checkbox", setting => { var checkBox = new CheckBox() { Text = setting.Title, Checked = GetSettingValue <bool>(setting.Name), AutoSize = true, UseVisualStyleBackColor = true }; checkBox.CheckedChanged += (s, e) => SetSettingValue(setting.Name, checkBox.Checked); return(checkBox); }); // Radio Group Builder EditorBuilders.Add("radio", setting => { var group = new GroupBox() { AutoSize = true, Text = setting.Title, Dock = DockStyle.Top }; FlowLayoutPanel panel = new FlowLayoutPanel() { AutoSize = true, FlowDirection = FlowDirection.TopDown, Dock = DockStyle.Fill }; object settingValue = GetSettingValue <object>(setting.Name); Array values = Enum.GetValues(settingValue.GetType()); foreach (var value in values) { RadioButton radio = new RadioButton() { Name = $"{setting.Name}.{value}", AutoSize = true, Checked = value.Equals(settingValue), Text = value.GetType() .GetMember(value.ToString()) .FirstOrDefault() ?.GetCustomAttribute <DescriptionAttribute>() ?.Description }; radio.CheckedChanged += (s, e) => { if (radio.Checked) { SetSettingValue(setting.Name, value); } }; panel.Controls.Add(radio); } group.Controls.Add(panel); return(group); }); // Textbox Builder EditorBuilders.Add("textbox", setting => { TextPicker picker = new TextPicker() { Title = setting.Title, SelectedValue = GetSettingValue <string>(setting.Name), Dock = DockStyle.Fill }; picker.SelectedValueChanged += (s, e) => SetSettingValue(setting.Name, picker.SelectedValue); return(picker); }); // Color Picker Builder EditorBuilders.Add("colorpicker", setting => { ColorPicker picker = new ColorPicker() { Text = setting.Title, SelectedValue = GetSettingValue <Color>(setting.Name), AutoSize = true }; picker.SelectedValueChanged += (s, e) => SetSettingValue(setting.Name, picker.SelectedValue); return(picker); }); // Font Picker Builder EditorBuilders.Add("fontpicker", setting => { Font font = GetSettingValue <Font>(setting.Name); FontPicker picker = new FontPicker() { Title = setting.Title, SelectedValue = font, Dock = DockStyle.Fill }; picker.SelectedValueChanged += (s, e) => SetSettingValue(setting.Name, picker.SelectedValue); return(picker); }); // Directory Picker Builder EditorBuilders.Add("directorypicker", setting => { string directory = GetSettingValue <string>(setting.Name); DirectoryPicker picker = new DirectoryPicker() { Title = setting.Title, SelectedValue = directory, Dock = DockStyle.Fill }; picker.SelectedValueChanged += (s, e) => SetSettingValue(setting.Name, picker.SelectedValue); return(picker); }); #endregion Default Control Builders }