HeaderPane
Main
Hide
Share Link
Print

DemoSample Sample (C#)

This sample shows standard controls, a slider and a range slider and buttons that open the message box, a task dialog and the color dialog, with options that change dark mode, high contrast and the look of the sliders. The SftStyle component on the form shows every form of the sample, the dialogs included, in the selected mode; the sliders follow it through their own SftSlider.DarkMode and SftSlider.HighContrastMode properties.

The source code is located at C:\Program Files (x86)\Softelvdm\SftStyle NET 3.0\Samples\CSharp\DemoSample\Form1.cs.

using System;
using System.Windows.Forms;

using Softelvdm.SftStyleNET;
using Softelvdm.SftStyleNET.Controls;

namespace DemoSample {
    public partial class Form1 : Form {

        public Form1() {
            InitializeComponent();

            comboCity.Items.AddRange(new object[] { "Orlando", "Ocala", "Oviedo", "Tampa", "Miami" });
            comboCity.SelectedIndex = 0;
            radioEmail.Checked = true;
            listOrders.Items.Add(new ListViewItem(new string[] { "1042", "Avery Johnson", "1,234.50" }));
            listOrders.Items.Add(new ListViewItem(new string[] { "1043", "Blake Rivera", "86.00" }));
            listOrders.Items.Add(new ListViewItem(new string[] { "1044", "Casey Morgan", "412.75" }));
            listOrders.Items.Add(new ListViewItem(new string[] { "1045", "Drew Patel", "2,050.00" }));

            FillCombo(comboDarkMode, typeof(DarkModeEnum), sftStyle1.DarkMode);
            FillCombo(comboHighContrast, typeof(HighContrastModeEnum), sftStyle1.HighContrastMode);
            FillCombo(comboLook, typeof(SliderLookEnum), sliderVolume.Look);
            ShowState();
            ShowSliders();
        }

        private void FillCombo(ComboBox combo, Type enumType, object current) {
            foreach (object value in Enum.GetValues(enumType))
                combo.Items.Add(value);
            combo.SelectedItem = current;
        }

        // The SftStyle component shows every form of the application in the selected mode. The sliders have a DarkMode and
        // HighContrastMode of their own, which follow the component's here.
        private void comboDarkMode_SelectedIndexChanged(object sender, EventArgs e) {
            DarkModeEnum mode = (DarkModeEnum)comboDarkMode.SelectedItem;
            sftStyle1.DarkMode = mode;
            sliderVolume.DarkMode = mode;
            sliderPrice.DarkMode = mode;
        }

        private void comboHighContrast_SelectedIndexChanged(object sender, EventArgs e) {
            HighContrastModeEnum mode = (HighContrastModeEnum)comboHighContrast.SelectedItem;
            sftStyle1.HighContrastMode = mode;
            sliderVolume.HighContrastMode = mode;
            sliderPrice.HighContrastMode = mode;
        }

        private void comboLook_SelectedIndexChanged(object sender, EventArgs e) {
            sliderVolume.Look = (SliderLookEnum)comboLook.SelectedItem;
            sliderPrice.Look = sliderVolume.Look;
        }

        private void sftStyle1_DarkModeChanged(object sender, EventArgs e) {
            ShowState();
        }

        private void sftStyle1_HighContrastChanged(object sender, EventArgs e) {
            ShowState();
        }

        // With Auto, the component follows the Windows settings, also when they change while the form is open.
        private void ShowState() {
            labelState.Text = "Dark mode is " + (sftStyle1.DarkModeActive ? "on" : "off") + ", high contrast is " + (sftStyle1.HighContrastActive ? "on" : "off") + ".";
        }

        private void sliderVolume_ValueChanged(object sender, EventArgs e) {
            ShowSliders();
        }

        private void sliderPrice_RangeChanged(object sender, EventArgs e) {
            ShowSliders();
        }

        private void ShowSliders() {
            labelSliders.Text = "Volume " + sliderVolume.Value + ", price range " + sliderPrice.LowerValue + " to " + sliderPrice.UpperValue;
        }

        // SftMessageBox takes the arguments of MessageBox.Show and returns the same results.
        private void buttonMessageBox_Click(object sender, EventArgs e) {
            DialogResult result = SftMessageBox.Show(this, "Do you want to save the changes to Order 1042 before closing?", "Orders",
                MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
            labelResult.Text = "Message box: " + result;
        }

        private void buttonTaskDialog_Click(object sender, EventArgs e) {
            SftTaskDialogPage page = new SftTaskDialogPage {
                Caption = "Unsaved orders",
                Heading = "What do you want to do with the 3 unsaved orders?",
                Icon = SftTaskDialogIcon.Warning,
                Verification = new SftTaskDialogVerificationCheckBox("&Do not ask again"),
                Expander = new SftTaskDialogExpander("Order 1042, Order 1044 and Order 1045 have changes that are not saved."),
                Footnote = new SftTaskDialogFootnote("Drafts are kept for 30 days."),
            };
            page.Buttons.Add(new SftTaskDialogCommandLinkButton("&Save the orders", "They are saved as drafts and can be completed later."));
            page.Buttons.Add(new SftTaskDialogCommandLinkButton("D&iscard the orders", "The changes are lost."));
            page.Buttons.Add(SftTaskDialogButton.Cancel);
            SftTaskDialogButton clicked = SftTaskDialog.ShowDialog(this, page);
            labelResult.Text = "Task dialog: " + (clicked == null ? "closed" : clicked.Text.Replace("&", "")) + (page.Verification.Checked ? ", do not ask again" : "");
        }

        private void buttonColorDialog_Click(object sender, EventArgs e) {
            sftColorDialog1.Color = panelColor.BackColor;
            if (sftColorDialog1.ShowDialog(this) == DialogResult.OK) {
                panelColor.BackColor = sftColorDialog1.Color;
                labelResult.Text = "Color dialog: " + sftColorDialog1.Color.Name;
            }
        }
    }
}