public void RefreshPreview()
        {
            if (nud_top.Value + nud_bottom.Value + nud_left.Value + nud_right.Value > LEDLimit)
            {
                MessageBox.Show("More than 64 LEDs are not supported!");
            }
            rf.regions.Clear();

            rf = new RegionFrame((int)nud_top.Value,
                                 (int)nud_bottom.Value,
                                 (int)nud_left.Value,
                                 (int)nud_right.Value, pbPreview.Width, pbPreview.Height, (int)nud_size.Value, (int)nud_shift.Value);
            CalculateDXRegions();
            SetColors();
            pbPreview.Image = DXScreen;
        }
        public MainForm()
        {
            log4net.Config.XmlConfigurator.Configure();
            log.Info("Starting BlinkStick Ambilight v." + Application.ProductVersion);
            foreach (var screen in Screen.AllScreens)
            {
                log.Debug("Screen (" + screen.DeviceName + ") Resolution: " + screen.WorkingArea.Width.ToString() + " / "
                          + screen.WorkingArea.Height.ToString());
            }
            try
            {
                DXInit();
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
            }
            InitializeComponent();

            about        = new AboutForm();
            currentcolor = new Color();

            this.Text = "BlinkStick AmbiLight v." + Application.ProductVersion + " (c) by René Kannegießer";

            glob               = new globalsettings();
            pbPreview.Width    = Screen.AllScreens[iScreen].Bounds.Width / preview_factor;
            pbPreview.Height   = Screen.AllScreens[iScreen].Bounds.Height / preview_factor;
            pbPreview.SizeMode = PictureBoxSizeMode.StretchImage;

            ScreenRect = new Rectangle(0, 0, Screen.AllScreens[iScreen].Bounds.Width / preview_factor,
                                       Screen.AllScreens[iScreen].Bounds.Height / preview_factor);

            this.Height           = 484;   //pbPreview.Height + 100;
            this.Width            = pbPreview.Width + 260;
            grpScreenPreview.Text = "Screen Preview (Resolution: " + Screen.AllScreens[iScreen].Bounds.Width.ToString() +
                                    " x " + Screen.AllScreens[iScreen].Bounds.Height.ToString() + ")";

            if (settings.LoadDat() == null)
            {
                glob = new globalsettings();
                FillSettings();
            }
            else
            {
                glob = settings.LoadDat().globalsettings;
            }

            rf = new RegionFrame((int)nud_top.Value,
                                 (int)nud_bottom.Value,
                                 (int)nud_left.Value,
                                 (int)nud_right.Value,
                                 pbPreview.Width,
                                 pbPreview.Height,
                                 (int)nud_size.Value,
                                 (int)nud_shift.Value);

            FillControls();

            if (cb_ConnectFirst.Checked)
            {
                RefreshDevices();
            }
            if (!IsDebug)
            {
                OpenDevice(comboBox1.Text);
            }
            valueRefresh = true;
            RefreshPreview();
        }