private void TextBoxTitleColor_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (TextBoxTitleColor.Text.Count() == 6)
     {
         RectangleTitleColor.Fill = MiscConverter.IntToSolidColorBrush(MiscConverter.StringToIntColor(TextBoxTitleColor.Text));
     }
 }
        // Thread threadRemote;


        public void GetTitleColor()
        {
            try {
                titleColor = MiscConverter.IntToSolidColorBrush(MiscConverter.StringToIntColor(Setting.GetAttribute("titleColor")));
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                titleColor = MiscConverter.IntToSolidColorBrush(0xffff00);
            }

            if (freePresentationText != null)
            {
                // free text presentation: don't change contents
                UpdateFree();
            }
            if (WrapPanelPageList != null && WrapPanelPageList.Children.Count > 1)
            {
                // if a text file is open, the minimum of Count is 2
                int len = textList.Count;
                for (int i = 1; i < len; i++)
                {
                    if (isTitleList[i])
                    {
                        (WrapPanelPageList.Children[i - 1] as Button).Foreground = titleColor;
                    }
                }
            }

            if (isTitleList != null)
            {
                if (PgmContent != null && isTitleList[pgmManager.PageNumber])
                {
                    PgmContent.Foreground = titleColor;
                    if (pw != null)
                    {
                        pw.LabelPresenterText.Foreground = titleColor;
                    }
                }

                if (PvwContent != null && isTitleList[pvwManager.PageNumber])
                {
                    PvwContent.Foreground = titleColor;
                }
            }
        }
        // Get and apply settings from Setting class to SettingWindow controls
        private void SettingToControl()
        {
            System.Windows.Forms.Screen[] sc = System.Windows.Forms.Screen.AllScreens;
            int    numOfScreen = sc.Length;
            double fullWidth = 0, fullHeight = 0, offsetX = 0, offsetY = 0;
            double dpiX           = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice.M11;
            double dpiY           = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice.M22;
            double threshold      = 6.25; // 500 / 80 = 6.25
            double multiplyFactor = 1.0;

            List <ScreenRect> actualScreenRectList = new List <ScreenRect>(numOfScreen);

            GetSettings();

            // for drawing screen map
            // get full size of all of the monitors
            // and get x, y offsets for negative positions
            for (int i = 0; i < numOfScreen; i++)
            {
                System.Drawing.Rectangle r = sc[i].Bounds;

                if (sc[i].Primary)
                {
                    if (offsetX > r.X)
                    {
                        offsetX = r.X;
                    }
                    if (offsetY > r.Y)
                    {
                        offsetY = r.Y;
                    }
                    if (fullWidth < r.Width)
                    {
                        fullWidth = r.X + r.Width;
                    }
                    if (fullHeight < r.Height)
                    {
                        fullHeight = r.Y + r.Height;
                    }
                    actualScreenRectList.Add(new ScreenRect(r.X, r.Y, r.Width, r.Height));
                }
                else
                {
                    double ithX          = r.X / dpiX;
                    double ithY          = r.Y / dpiY;
                    double ithWidth      = r.Width / dpiX;
                    double ithHeight     = r.Height / dpiY;
                    double ithFullWidth  = ithX + ithWidth;
                    double ithFullHeight = ithY + ithHeight;
                    if (offsetX > ithX)
                    {
                        offsetX = ithX;
                    }
                    if (offsetY > ithY)
                    {
                        offsetY = ithY;
                    }
                    if (fullWidth < ithFullWidth)
                    {
                        fullWidth = ithFullWidth;
                    }
                    if (fullHeight < ithFullHeight)
                    {
                        fullHeight = ithFullHeight;
                    }
                    actualScreenRectList.Add(new ScreenRect(ithX, ithY, ithWidth, ithHeight));
                }
            }
            offsetX    *= -1;
            offsetY    *= -1;
            fullWidth  += offsetX;
            fullHeight += offsetY;
            // calculate multiply factor
            if (fullWidth / fullHeight <= threshold)
            {
                multiplyFactor = 80.0 / fullHeight;
            }
            else
            {
                multiplyFactor = 500.0 / fullWidth;
            }

            // construct screen combo box and draw screen map
            ComboBoxPresenterScreen.Items.Clear();
            CanvasScreens.Children.Clear();
            for (int i = 0; i < numOfScreen; i++)
            {
                System.Drawing.Rectangle r = sc[i].Bounds;
                double ithWidth            = actualScreenRectList[i].width;
                double ithHeight           = actualScreenRectList[i].height;
                double ithX = actualScreenRectList[i].x;
                double ithY = actualScreenRectList[i].y;

                // combo box item
                ComboBoxItem cbi = new ComboBoxItem {
                    Content = "(" + (i + 1).ToString() + ") " + sc[i].DeviceName + ": " + ithWidth.ToString() + "×" + ithHeight.ToString() + " (" + ithX.ToString() + "," + ithY.ToString() + ")"
                };
                ComboBoxPresenterScreen.Items.Add(cbi);

                // screen map item as button
                Style screenBorderStyle = FindResource("ScreenBorder") as Style;
                System.Windows.Controls.Primitives.ToggleButton btn = new System.Windows.Controls.Primitives.ToggleButton {
                    Style   = screenBorderStyle,
                    Content = (i + 1).ToString(),
                    Width   = ithWidth * multiplyFactor,
                    Height  = ithHeight * multiplyFactor,
                    Tag     = i,
                };
                btn.Click += ScreenBorder_Click;
                Canvas.SetLeft(btn, 5 + (ithX + offsetX) * multiplyFactor);
                Canvas.SetTop(btn, 5 + (ithY + offsetY) * multiplyFactor);
                CanvasScreens.Children.Add(btn);
            }
            if (presenterScreen <= numOfScreen)
            {
                ComboBoxPresenterScreen.SelectedIndex = presenterScreen - 1;
            }
            else
            {
                ComboBoxPresenterScreen.SelectedIndex = numOfScreen - 1;
            }
            (CanvasScreens.Children[ComboBoxPresenterScreen.SelectedIndex] as System.Windows.Controls.Primitives.ToggleButton).IsChecked = true;

            // textEncoding = ComboBoxTextEncoding.SelectedIndex;
            switch (textEncoding)
            {
            case 1200:     // UTF-16 LE
                ComboBoxTextEncoding.SelectedIndex = 2;
                break;

            case 1201:     // UTF-16 BE
                ComboBoxTextEncoding.SelectedIndex = 3;
                break;

            case 65001:     // UTF-8
                ComboBoxTextEncoding.SelectedIndex = 1;
                break;

            default:
                ComboBoxTextEncoding.SelectedIndex = 0;
                break;
            }

            switch (textPosition)
            {
            case 1:
                RadioButtonTextPosition1.IsChecked = true;
                break;

            case 2:
                RadioButtonTextPosition2.IsChecked = true;
                break;

            case 3:
                RadioButtonTextPosition3.IsChecked = true;
                break;

            case 4:
                RadioButtonTextPosition4.IsChecked = true;
                break;

            case 5:
                RadioButtonTextPosition5.IsChecked = true;
                break;

            case 6:
                RadioButtonTextPosition6.IsChecked = true;
                break;

            case 7:
                RadioButtonTextPosition7.IsChecked = true;
                break;

            case 8:
                RadioButtonTextPosition8.IsChecked = true;
                break;

            case 9:
                RadioButtonTextPosition9.IsChecked = true;
                break;
            }

            CheckBoxScreenRatioSimulation.IsChecked = screenRatioSimulation;
            TextBoxScreenWidth.Text         = screenRatioSimulationWidth.ToString();
            TextBoxScreenHeight.Text        = screenRatioSimulationHeight.ToString();
            ComboBoxTextAlign.SelectedIndex = textAlign - 1;
            UpdateButtonChangeFont();
            TextBoxFontSize.Text       = fontSize.ToString();
            TextBoxTitleColor.Text     = titleColor.ToString("X6");
            RectangleTitleColor.Fill   = MiscConverter.IntToSolidColorBrush(titleColor);
            TextBoxLineHeight.Text     = lineHeight.ToString();
            TextBoxMarginBasic.Text    = marginBasic.ToString();
            TextBoxMarginOverflow.Text = marginOverflow.ToString();
        }