/// <summary>
        /// 设置背景拉伸方式
        /// </summary>
        private void Se_ComboBox_Background_Stretch_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var bg = IniFileIo.IniFileReadString("DedicatedServerConfigure", "Skin", "Background");

            if (!MwInit)
            {
                return;
            }
            if (bg == "")
            {
                Se_button_Background_Clear_Click(null, null);
            }
            else
            {
                SeBgAlphaText.Foreground = Brushes.Black;
                try
                {
                    var brush = new ImageBrush()
                    {
                        ImageSource = new BitmapImage(new Uri(bg)),
                        Stretch     = (Stretch)SeComboBoxBackgroundStretch.SelectedIndex
                    };
                    UiBackGroundBorder.Background = brush;
                    UiTitle.Foreground            = new SolidColorBrush(Colors.Black);
                    IniFileIo.IniFileWrite("DedicatedServerConfigure", "Skin", "BackgroundStretch", (SeComboBoxBackgroundStretch.SelectedIndex + 1).ToString());
                }
                catch
                {
                    Se_button_Background_Clear_Click(null, null);
                }
            }
        }
 /// <summary>
 /// 修改淡紫色透明光标
 /// </summary>
 private void SeCheckBoxLavenderCursor_Click(object sender, RoutedEventArgs e)
 {
     // TODO 提示框
     //var copySplashWindow = new CopySplashScreen("重启生效");
     //copySplashWindow.InitializeComponent();
     //copySplashWindow.ContentTextBlock.FontSize = 20;
     //copySplashWindow.Show();
     IniFileIo.IniFileWrite("DedicatedServerConfigure", "Others", "LavenderCursor", SeCheckBoxLavenderCursor.IsChecked.ToString());
 }
        /// <summary>
        /// 清除背景
        /// </summary>
        private void Se_button_Background_Clear_Click(object sender, RoutedEventArgs e)
        {
            var brush = new ImageBrush
            {
                ImageSource = new BitmapImage(new Uri("pack://application:,,,/饥荒开服工具ByTpxxn;component/Resources/DefaultBackground.jpg", UriKind.RelativeOrAbsolute))
            };

            UiBackGroundBorder.Background = brush;
            UiTitle.Foreground            = new SolidColorBrush(Colors.White);
            IniFileIo.IniFileWrite("DedicatedServerConfigure", "Skin", "Background", "");
        }
        /// <summary>
        /// 切换鼠标指针为默认状态
        /// </summary>
        private void MainWindow_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Cursor = ((TextBlock)CursorDictionary["CursorPointer"]).Cursor;
            var dictionary = new Dictionary <string, string>
            {
                { "Width", ActualWidth.ToString(CultureInfo.InvariantCulture) },
                { "Height", ActualHeight.ToString(CultureInfo.InvariantCulture) }
            };

            IniFileIo.IniFileWrite("DedicatedServerConfigure", "Window", dictionary);
        }
 /// <summary>
 /// 修改字体加粗
 /// </summary>
 private void Se_CheckBox_FontWeight_Click(object sender, RoutedEventArgs e)
 {
     if (!LoadFont)
     {
         return;
     }
     mainWindow.FontWeight = SeCheckBoxFontWeight.IsChecked == true ? FontWeights.Bold : FontWeights.Normal;
     ((TextBlock)((VisualBrush)FindResource("HelpBrush")).Visual).FontWeight = mainWindow.FontWeight;
     Global.FontWeight = mainWindow.FontWeight;
     IniFileIo.IniFileWrite("DedicatedServerConfigure", "Font", "FontWeight", SeCheckBoxFontWeight.IsChecked.ToString());
 }
        /// <summary>
        /// 修改字体
        /// </summary>
        private void Se_ComboBox_Font_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!LoadFont)
            {
                return;
            }
            var textList = (from TextBlock textBlock in SeComboBoxFont.Items select textBlock.Text).ToList();

            mainWindow.FontFamily = new FontFamily(textList[SeComboBoxFont.SelectedIndex]);
            ((TextBlock)((VisualBrush)FindResource("HelpBrush")).Visual).FontFamily = mainWindow.FontFamily;
            Global.FontFamily = mainWindow.FontFamily;
            IniFileIo.IniFileWrite("DedicatedServerConfigure", "Font", "FontFamily", textList[SeComboBoxFont.SelectedIndex]);
        }
 /// <summary>
 /// 窗口置顶
 /// </summary>
 private void Se_button_Topmost_Click(object sender, RoutedEventArgs e)
 {
     if (Topmost == false)
     {
         Topmost = true;
         SeImageTopmost.Source   = new BitmapImage(new Uri("pack://application:,,,/饥荒开服工具ByTpxxn;component/Resources/Setting_Top_T.png", UriKind.Absolute));
         SeTextblockTopmost.Text = "永远置顶";
         IniFileIo.IniFileWrite("DedicatedServerConfigure", "Others", "Topmost", "1");
     }
     else
     {
         Topmost = false;
         SeImageTopmost.Source   = new BitmapImage(new Uri("pack://application:,,,/饥荒开服工具ByTpxxn;component/Resources/Setting_Top_F.png", UriKind.Absolute));
         SeTextblockTopmost.Text = "永不置顶";
         IniFileIo.IniFileWrite("DedicatedServerConfigure", "Others", "Topmost", "0");
     }
 }
        /// <summary>
        /// 设置背景
        /// </summary>
        private void Se_button_Background_Click(object sender, RoutedEventArgs e)
        {
            var openFileDialog = new Microsoft.Win32.OpenFileDialog()
            {
                Title      = "选择背景图片",
                FileName   = "",                                                                    //默认文件名
                DefaultExt = ".png",                                                                // 默认文件扩展名
                Filter     = "图像文件 (*.bmp;*.gif;*.jpg;*.jpeg;*.png)|*.bmp;*.gif;*.jpg;*.jpeg;*.png" //文件扩展名过滤器
            };
            // ReSharper disable once UnusedVariable
            var result = openFileDialog.ShowDialog(); //显示打开文件对话框

            UiBackGroundBorder.Visibility = Visibility.Visible;
            try
            {
                var pictruePath = Environment.CurrentDirectory + @"\Background\"; //设置文件夹位置
                if (Directory.Exists(pictruePath) == false)                       //若文件夹不存在
                {
                    Directory.CreateDirectory(pictruePath);
                }
                var filename = Path.GetFileName(openFileDialog.FileName); //设置文件名
                try
                {
                    File.Copy(openFileDialog.FileName, pictruePath + filename, true);
                }
                catch (Exception)
                {
                    // ignored
                }
                var brush = new ImageBrush
                {
                    ImageSource = new BitmapImage(new Uri(pictruePath + filename))
                };
                UiBackGroundBorder.Background = brush;
                UiTitle.Foreground            = new SolidColorBrush(Colors.Black);
                IniFileIo.IniFileWrite("DedicatedServerConfigure", "Skin", "Background", pictruePath + filename);
            }
            catch (Exception)
            {
                MessageBox.Show("没有选择正确的图片ヽ(゚Д゚)ノ");
            }
        }
 /// <summary>
 /// MainWindow窗口加载
 /// </summary>
 private void MainWindow_Loaded(object sender, RoutedEventArgs e)
 {
     #region 加载字体
     foreach (var str in ReadFont())
     {
         var textBlock = new TextBlock
         {
             Text       = str,
             FontFamily = new FontFamily(str)
         };
         SeComboBoxFont.Items.Add(textBlock);
     }
     var mainWindowFont = IniFileIo.IniFileReadString("DedicatedServerConfigure", "Font", "FontFamily");
     var stringList     = (from TextBlock textBlock in SeComboBoxFont.Items select textBlock.Text).ToList();
     SeComboBoxFont.SelectedIndex = stringList.IndexOf(mainWindowFont);
     var mainWindowFontWeight = IniFileIo.IniFileReadString("DedicatedServerConfigure", "Font", "FontWeight");
     SeCheckBoxFontWeight.IsChecked = mainWindowFontWeight == "True";
     LoadFont = true;
     #endregion
 }
        private void ResizeWindow(ResizeDirection direction)
        {
            SendMessage(_hwndSource.Handle, WmSyscommand, (IntPtr)(61440 + direction), IntPtr.Zero);
            var systemWorkAreaRect = SystemParameters.WorkArea;

            if (Width == systemWorkAreaRect.Width && Height == systemWorkAreaRect.Height)
            {
                UiBtnMaximized.Visibility = Visibility.Collapsed;
                UiBtnNormal.Visibility    = Visibility.Visible;
            }
            else
            {
                UiBtnMaximized.Visibility = Visibility.Visible;
                UiBtnNormal.Visibility    = Visibility.Collapsed;
            }
            var dictionary = new Dictionary <string, string>
            {
                { "Width", ActualWidth.ToString(CultureInfo.InvariantCulture) },
                { "Height", ActualHeight.ToString(CultureInfo.InvariantCulture) }
            };

            IniFileIo.IniFileWrite("DedicatedServerConfigure", "Window", dictionary);
        }
            private static void App_Startup(object sender, StartupEventArgs e)
            {
                #region 设置全局字体
                var mainWindowFont = IniFileIo.IniFileReadString("DedicatedServerConfigure", "Font", "FontFamily");
                Global.FontFamily = !string.IsNullOrEmpty(mainWindowFont) ? new FontFamily(mainWindowFont) : new FontFamily("微软雅黑");
                #endregion

                #region 淡紫色透明光标
                var mainWindowLavenderCursor = IniFileIo.IniFileReadString("DedicatedServerConfigure", "Others", "LavenderCursor");
                if (string.IsNullOrEmpty(mainWindowLavenderCursor))
                {
                    mainWindowLavenderCursor = "True";
                    IniFileIo.IniFileWrite("DedicatedServerConfigure", "Others", "LavenderCursor", "True");
                }
                ResourceDictionary CursorDictionary;
                if (mainWindowLavenderCursor == "True")
                {
                    CursorDictionary = new ResourceDictionary
                    {
                        Source = new Uri(
                            "pack://application:,,,/饥荒开服工具ByTpxxn;component/Dictionary/Cursor/CursorDictionary.xaml",
                            UriKind.Absolute)
                    };
                }
                else
                {
                    CursorDictionary = new ResourceDictionary
                    {
                        Source = new Uri(
                            "pack://application:,,,/饥荒开服工具ByTpxxn;component/Dictionary/Cursor/DefaultCursorDictionary.xaml",
                            UriKind.Absolute)
                    };
                    Current.Resources.MergedDictionaries.Add(CursorDictionary);
                }
                foreach (var key in CursorDictionary.Keys)
                {
                    var cursor = ((TextBlock)CursorDictionary[key]).Cursor;
                    CursorDictionary.Remove(key);
                    CursorDictionary.Add(key, cursor);
                }
                Current.Resources.MergedDictionaries.Add(CursorDictionary);
                #endregion

                #region 读取资源字典
                var resourceDictionaries = new Collection <ResourceDictionary>
                {
                    new ResourceDictionary
                    {
                        Source = new Uri(
                            "pack://application:,,,/饥荒开服工具ByTpxxn;component/Dictionary/ComboBoxDictionary.xaml",
                            UriKind.Absolute)
                    },
                    new ResourceDictionary
                    {
                        Source = new Uri(
                            "pack://application:,,,/饥荒开服工具ByTpxxn;component/Dictionary/WindowDictionary.xaml",
                            UriKind.Absolute)
                    },
                    new ResourceDictionary
                    {
                        Source = new Uri(
                            "pack://application:,,,/饥荒开服工具ByTpxxn;component/Dictionary/DediLeftPanelRadioButtonDictionary.xaml",
                            UriKind.Absolute)
                    },
                    new ResourceDictionary
                    {
                        Source = new Uri(
                            "pack://application:,,,/饥荒开服工具ByTpxxn;component/Dictionary/DediModBoxDictionary.xaml",
                            UriKind.Absolute)
                    },
                    new ResourceDictionary
                    {
                        Source = new Uri(
                            "pack://application:,,,/饥荒开服工具ByTpxxn;component/Dictionary/DediRightPanelButtonDictionary.xaml",
                            UriKind.Absolute)
                    },
                    new ResourceDictionary
                    {
                        Source = new Uri(
                            "pack://application:,,,/饥荒开服工具ByTpxxn;component/Dictionary/DediRightPanelRadioButtonDictionary.xaml",
                            UriKind.Absolute)
                    },
                    new ResourceDictionary
                    {
                        Source = new Uri(
                            "pack://application:,,,/饥荒开服工具ByTpxxn;component/Dictionary/DediRightPanelTextBoxDictionary.xaml",
                            UriKind.Absolute)
                    },
                    new ResourceDictionary
                    {
                        Source = new Uri(
                            "pack://application:,,,/饥荒开服工具ByTpxxn;component/Dictionary/DediScrollViewerDictionary.xaml",
                            UriKind.Absolute)
                    },
                    new ResourceDictionary
                    {
                        Source = new Uri(
                            "pack://application:,,,/饥荒开服工具ByTpxxn;component/Dictionary/DediSelectBoxDictionary.xaml",
                            UriKind.Absolute)
                    }
                };
                foreach (var resourceDictionary in resourceDictionaries)
                {
                    Current.Resources.MergedDictionaries.Add(resourceDictionary);
                }
                #endregion

                var mainWindowShow = new MainWindow();
                mainWindowShow.InitializeComponent();
                mainWindowShow.Show();
                mainWindowShow.Activate();
            }
 /// <summary>
 /// 设置窗口透明度
 /// </summary>
 private void Se_Window_Alpha_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
 {
     Opacity = SeWindowAlpha.Value / 100;
     SeWindowAlphaText.Text = "窗口不透明度:" + (int)SeWindowAlpha.Value + "%";
     IniFileIo.IniFileWrite("DedicatedServerConfigure", "Skin", "WindowAlpha", (SeWindowAlpha.Value + 1).ToString(CultureInfo.InvariantCulture));
 }
 /// <summary>
 /// 设置背景透明度
 /// </summary>
 private void Se_BG_Alpha_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
 {
     UiBackGroundBorder.Opacity = SeBgAlpha.Value / 100;
     SeBgAlphaText.Text         = "背景不透明度:" + (int)SeBgAlpha.Value + "%";
     IniFileIo.IniFileWrite("DedicatedServerConfigure", "Skin", "BackgroundAlpha", (SeBgAlpha.Value + 1).ToString(CultureInfo.InvariantCulture));
 }
 public MainWindow()
 {
     Application.Current.MainWindow = this;
     #region "读取注册表(必须在初始化之前读取)"
     // 背景图片
     var bg        = IniFileIo.IniFileReadString("DedicatedServerConfigure", "Skin", "Background");
     var bgStretch = IniFileIo.IniFileReadDouble("DedicatedServerConfigure", "Skin", "BackgroundStretch");
     // 透明度
     var bgAlpha = IniFileIo.IniFileReadDouble("DedicatedServerConfigure", "Skin", "BackgroundAlpha");
     //var bgPanelAlpha = RegeditRw.RegRead("BGPanelAlpha");
     var windowAlpha = IniFileIo.IniFileReadDouble("DedicatedServerConfigure", "Skin", "WindowAlpha");
     // 窗口大小
     var mainWindowHeight = IniFileIo.IniFileReadDouble("DedicatedServerConfigure", "Window", "Height");
     var mainWindowWidth  = IniFileIo.IniFileReadDouble("DedicatedServerConfigure", "Window", "Width");
     // 字体
     var mainWindowFont       = IniFileIo.IniFileReadString("DedicatedServerConfigure", "Font", "FontFamily");
     var mainWindowFontWeight = IniFileIo.IniFileReadString("DedicatedServerConfigure", "Font", "FontWeight");
     // 淡紫色透明光标
     var mainWindowLavenderCursor = IniFileIo.IniFileReadString("DedicatedServerConfigure", "Others", "LavenderCursor");
     // 设置菜单
     var winTopmost = IniFileIo.IniFileReadDouble("DedicatedServerConfigure", "Others", "Topmost");
     // 设置
     //Settings.HideToNotifyIcon = RegeditRw.RegReadString("HideToNotifyIcon") == "True";
     //Settings.HideToNotifyIconPrompt = RegeditRw.RegReadString("HideToNotifyIconPrompt") == "True";
     //Settings.SmallButtonMode = RegeditRw.RegReadString("SmallButtonMode") == "True";
     #endregion
     // 初始化
     InitializeComponent();
     // 窗口缩放
     SourceInitialized += delegate(object sender, EventArgs e) { _hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; };
     MouseMove         += Window_MouseMove;
     // mainWindow初始化标志
     MwInit = true;
     #region "读取设置"
     // 设置字体
     if (string.IsNullOrEmpty(mainWindowFont))
     {
         IniFileIo.IniFileWrite("DedicatedServerConfigure", "Font", "FontFamily", "微软雅黑");
         mainWindowFont = "微软雅黑";
     }
     mainWindow.FontFamily = new FontFamily(mainWindowFont);
     ((TextBlock)((VisualBrush)FindResource("HelpBrush")).Visual).FontFamily = mainWindow.FontFamily;
     // 设置字体加粗
     if (string.IsNullOrEmpty(mainWindowFontWeight))
     {
         IniFileIo.IniFileWrite("DedicatedServerConfigure", "Font", "FontWeight", "False");
     }
     mainWindow.FontWeight = mainWindowFontWeight == "True" ? FontWeights.Bold : FontWeights.Normal;
     ((TextBlock)((VisualBrush)FindResource("HelpBrush")).Visual).FontWeight = mainWindow.FontWeight;
     Global.FontWeight = mainWindow.FontWeight;
     // 设置淡紫色透明光标
     SeCheckBoxLavenderCursor.IsChecked = mainWindowLavenderCursor == "True";
     // 版本初始化
     UiTitle.Text = "饥荒开服工具" + Assembly.GetExecutingAssembly().GetName().Version;
     // 窗口可视化计时器
     _visiTimer.Enabled  = true;
     _visiTimer.Interval = 200;
     _visiTimer.Tick    += VisiTimerEvent;
     _visiTimer.Start();
     // 设置光标资源字典路径
     if (SeCheckBoxLavenderCursor.IsChecked == true)
     {
         CursorDictionary.Source =
             new Uri("pack://application:,,,/饥荒开服工具ByTpxxn;component/Dictionary/Cursor/CursorDictionary.xaml",
                     UriKind.Absolute);
     }
     else
     {
         CursorDictionary.Source =
             new Uri("pack://application:,,,/饥荒开服工具ByTpxxn;component/Dictionary/Cursor/DefaultCursorDictionary.xaml",
                     UriKind.Absolute);
     }
     // 显示窗口
     MwVisibility = true;
     // 窗口置顶
     if (winTopmost == 1)
     {
         Se_button_Topmost_Click(null, null);
     }
     // 设置背景
     if (bg == "")
     {
         Se_button_Background_Clear_Click(null, null);
     }
     else
     {
         try
         {
             var brush = new ImageBrush
             {
                 ImageSource = new BitmapImage(new Uri(bg))
             };
             UiBackGroundBorder.Background = brush;
             UiTitle.Foreground            = new SolidColorBrush(Colors.Black);
         }
         catch
         {
             Se_button_Background_Clear_Click(null, null);
         }
     }
     // 设置背景拉伸方式
     if (bgStretch == 0)
     {
         bgStretch = 2;
     }
     SeComboBoxBackgroundStretch.SelectedIndex = (int)bgStretch - 1;
     // 设置背景透明度
     if (bgAlpha == 0)
     {
         bgAlpha = 101;
     }
     SeBgAlpha.Value            = bgAlpha - 1;
     SeBgAlphaText.Text         = "背景不透明度:" + (int)SeBgAlpha.Value + "%";
     UiBackGroundBorder.Opacity = (bgAlpha - 1) / 100;
     // 设置面板透明度
     //if (bgPanelAlpha == 0)
     //{
     //    bgPanelAlpha = 61;
     //}
     //SePanelAlpha.Value = bgPanelAlpha - 1;
     //SePanelAlphaText.Text = "面板不透明度:" + (int)SePanelAlpha.Value + "%";
     // 设置窗口透明度
     if (windowAlpha == 0)
     {
         windowAlpha = 101;
     }
     SeWindowAlpha.Value    = windowAlpha - 1;
     SeWindowAlphaText.Text = "窗口不透明度:" + (int)SeWindowAlpha.Value + "%";
     Opacity = (windowAlpha - 1) / 100;
     // 设置高度和宽度
     Width  = mainWindowWidth;
     Height = mainWindowHeight;
     #endregion
     // 设置托盘区图标
     //SetNotifyIcon();
     // Frame导航
     Global.DedicatedServerFrame = DedicatedServerFrame;
     DedicatedServerFrame.Navigate(new DedicatedServerPage());
     // 是否显示开服工具
     //if (Global.TestMode)
     //    SidebarDedicatedServer.Visibility = Visibility.Visible;
     // 检测新版本
     //UpdatePan.UpdateNow();
 }