using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Runtime.Remoting.Activation;
using IWshRuntimeLibrary;
using File = System.IO.File;
using TranslationAPI.Properties;
using System.Security.Principal;
using System.Runtime.CompilerServices;

namespace TranslationAPI
{
    public partial class MainForm : Form
    {
        //-------------Private变量--------------
        private WinTC winTC;
        private Thread GetClipBD;
        private Thread Download;
        private static Font ButtonTextFont;
        private static Font SmallButtonTextFont;
        private Button btn_SwitchColor;
        private Button btn_ChangeSize;
        private Button btn_BackToMenu;
        private Button btn_LineColor;
        private Button btn_TextColor;
        private Button btn_BGColor;
        private Button btn_StartUp;
        private Point mouseLocation;
        private bool isDragging;
        private bool Isdifferent = false;
        private bool EnableFT = true;
        private bool StartUp;
        private string ClipBoardConent;
        private string CommonPath = Application.UserAppDataPath.Substring(0, Application.UserAppDataPath.LastIndexOf(@"\"));
        private const int CS_DropSHADOW = 0x20000;
        private const int GCL_STYLE = (-26);
        private const double PrmSW = 2560d;
        private const double PrmSH = 1440d;
        private const double PrmW = 540d;
        private const double PrmH = 410d;
        //-------------Public变量---------------
        public static Color LineColor;
        public static Color TextColor;
        public static Color BGColor;
        public enum ThemeType
        {
            Light,
            Dark,
            SelfEdit
        }
        public static ThemeType themeType;
        public static int SW;
        public static int SH;
        public static float WinTCTextSize = 13;
        public static int MaxSize = 155;
        public MainForm()
        {
            InitializeComponent();
        }
        //-----------------以下方法----------------
        public static int HttpGet(string url, out string reslut)
        {
            reslut = "";
            try
            {
                HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.Create(url);
                wbRequest.Proxy = null;
                wbRequest.Method = "GET";
                wbRequest.ContentType = "text/html;charset=UTF-8";
                HttpWebResponse wbResponse = (HttpWebResponse)wbRequest.GetResponse();
                using (Stream responseStream = wbResponse.GetResponseStream())
                {
                    using (StreamReader sReader = new StreamReader(responseStream))
                    {
                        reslut = sReader.ReadToEnd();
                    }
                }
            }
            catch (Exception e)
            {
                reslut = e.Message;     //输出捕获到的异常，用OUT关键字输出
                return -1;              //出现异常，函数的返回值为-1
            }
            return 0;
        }//http的GET方法请求
        public static string GetMD5WithString(String input)
        {
            MD5 md5Hash = MD5.Create();
            // 将输入字符串转换为字节数组并计算哈希数据  
            byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
            // 创建一个 Stringbuilder 来收集字节并创建字符串  
            StringBuilder str = new StringBuilder();
            // 循环遍历哈希数据的每一个字节并格式化为十六进制字符串  
            for (int i = 0; i < data.Length; i++)
            {
                str.Append(data[i].ToString("x2"));//加密结果"x2"结果为32位,"x3"结果为48位,"x4"结果为64位
            }
            // 返回十六进制字符串  
            return str.ToString();
        }//将string加密为MD5
        public static string SummonLongRandomCode()
        {
            Random r = new Random();
            return $"{r.Next(1000, 1000000)}{r.Next(1000, 1000000)}";
        }//以string生成随机的长随机数
        public static string ConvertUnicodeToUtf8(string unicode)
        {
            if (string.IsNullOrEmpty(unicode))
            {
                return string.Empty;
            }
            return new Regex(@"\\u([0-9A-F]{4})", RegexOptions.IgnoreCase | RegexOptions.Compiled).Replace(unicode, p => Convert.ToChar(Convert.ToUInt16(p.Result("$1"), 16)).ToString());
        }//将Unicode编码转为UTF-8编码
        public static string GetClipBoardContent()
        {
            if (Clipboard.ContainsText())
            {
                return Clipboard.GetText();
            }
            else
            {
                return string.Empty;
            }
        }//获取剪切板内容
        public static void WriteIn(string Name, string txt)
        {
            FileInfo rd = new FileInfo(Name);
            StreamWriter sw = rd.CreateText();
            sw.WriteLine(txt);
            sw.Flush();
            sw.Close();
        }//写入文件
        public static bool ReadIn(string Name, out string Content)
        {
            FileInfo rd = new FileInfo(Name);
            if (rd.Exists)
            {
                StreamReader sr = rd.OpenText();
                Content = sr.ReadLine();
                sr.Close();
                return true;
            }
            else
            {
                Content = string.Empty;
                return false;
            }
        }//读取文件
        public static void CheckAppDate()
        {
            if (!Directory.Exists(Application.UserAppDataPath.Substring(0, Application.UserAppDataPath.LastIndexOf(@"\")) + @"\UserSelfEditData"))
            {
                Directory.CreateDirectory(Application.UserAppDataPath.Substring(0, Application.UserAppDataPath.LastIndexOf(@"\")) + @"\UserSelfEditData");
            }
            if (!Directory.Exists(Application.UserAppDataPath))
            {
                Directory.CreateDirectory(Application.UserAppDataPath);
            }
        }//检测是否存在配置文件夹否则创建
        public static Color BringStringToColor(string stringColor)
        {
            Color color = new Color();
            string[] Sstring = stringColor.Split(new char[] { ',' });
            color = Color.FromArgb(int.Parse(Sstring[0]), int.Parse(Sstring[1]), int.Parse(Sstring[2]));
            return color;
        }//将String数组颜色值转换为颜色类型
        public static string BringColorToString(Color color)
        {
            return $"{color.R},{color.G},{color.B}";
        }//将颜色值转换为String类型的字符串
        public static string OutPutThemeColor(ThemeType themeType)
        {
            if (themeType == ThemeType.Light)
            {
                return "0";
            }
            else if (themeType == ThemeType.Dark)
            {
                return "1";
            }
            else
            {
                return "2";
            }
        }//根据枚举类型ThemeType输出对应的String类型的值
        public static string OutPutBoolInString(bool Bo)
        {
            if (Bo)
            {
                return "true";
            }
            else
            {
                return "false";
            }
        }//将bool值类型转换为string类型字符串输出
        public static void CreateShortCut(string Path, string Argument)
        {
            WshShell wshShell = new WshShell();
            IWshShortcut wshShortcut = (IWshShortcut)wshShell.CreateShortcut(Path + "\\XFE划词翻译.lnk");
            //设置快捷方式的目标所在的位置(源程序完整路径)
            wshShortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            //当用户没有指定一个具体的目录时，快捷方式的目标应用程序将使用该属性所指定的目录来装载或保存文件。
            wshShortcut.WorkingDirectory = System.Environment.CurrentDirectory;
            //目标应用程序窗口类型(1.Normal window普通窗口,3.Maximized最大化窗口,7.Minimized最小化)
            wshShortcut.WindowStyle = 1;
            //快捷方式的描述
            wshShortcut.Description = "划词翻译软件-XFEstudio";
            //设置应用程序的启动参数
            wshShortcut.Arguments = Argument;
            //保存快捷方式
            wshShortcut.Save();
        }//在Path目录下创建本程序的快捷方式
        public void ChangeButtonColor(Color Text, Color Back, Color MDown, Color MOver, Color Line)
        {
            //----------切换开关-----------
            btn_Switch.ForeColor = Text;
            btn_Switch.BackColor = Back;
            btn_Switch.FlatAppearance.MouseDownBackColor = MDown;
            btn_Switch.FlatAppearance.MouseOverBackColor = MOver;
            btn_Switch.FlatAppearance.BorderColor = Line;
            //----------设置选项-----------
            btn_Option.ForeColor = Text;
            btn_Option.BackColor = Back;
            btn_Option.FlatAppearance.MouseDownBackColor = MDown;
            btn_Option.FlatAppearance.MouseOverBackColor = MOver;
            btn_Option.FlatAppearance.BorderColor = Line;
            //----------帮助说明-----------
            btn_Help.ForeColor = Text;
            btn_Help.BackColor = Back;
            btn_Help.FlatAppearance.MouseDownBackColor = MDown;
            btn_Help.FlatAppearance.MouseOverBackColor = MOver;
            btn_Help.FlatAppearance.BorderColor = Line;
        }//改变所有按钮颜色
        //------------------主窗体-----------------
        private void Form1_Load(object sender, EventArgs e)
        {
            string Colorstring;
            //----------------自适应屏幕----------------
            SH = Screen.PrimaryScreen.Bounds.Height;
            SW = Screen.PrimaryScreen.Bounds.Width;
            double SWP = PrmW / PrmSW;//屏幕宽比例
            double SHP = PrmH / PrmSH;//屏幕长比例
            this.Width = (int)(SW * SWP);
            this.Height = (int)(SH * SHP);
            btn_Switch.Size = new Size((int)(btn_Switch.Size.Width / PrmSW * SW), (int)(btn_Switch.Size.Height / PrmSH * SH));
            btn_Option.Size = new Size((int)(btn_Option.Size.Width / PrmSW * SW), (int)(btn_Option.Size.Height / PrmSH * SH));
            btn_Help.Size = new Size((int)(btn_Help.Size.Width / PrmSW * SW), (int)(btn_Help.Size.Height / PrmSH * SH));
            btn_Small.Size = new Size((int)(btn_Small.Size.Width / PrmSW * SW), (int)(btn_Small.Size.Height / PrmSH * SH));
            btn_Close.Size = new Size((int)(btn_Close.Size.Width / PrmSW * SW), (int)(btn_Close.Size.Height / PrmSH * SH));
            //-----------------设置字体------------------
            ButtonTextFont = new Font("等线", (float)(22 / PrmSW * SW), FontStyle.Bold);
            SmallButtonTextFont = new Font("等线", (float)(18 / PrmSW * SW), FontStyle.Bold);
            btn_Switch.Font = new Font("等线", (float)(btn_Switch.Font.Size / PrmSW * SW), FontStyle.Bold);
            btn_Option.Font = new Font("等线", (float)(btn_Option.Font.Size / PrmSW * SW), FontStyle.Bold);
            btn_Help.Font = new Font("等线", (float)(btn_Help.Font.Size / PrmSW * SW), FontStyle.Bold);
            btn_Small.Font = new Font("等线", (float)(btn_Small.Font.Size / PrmSW * SW), FontStyle.Bold);
            btn_Close.Font = new Font("等线", (float)(btn_Close.Font.Size / PrmSW * SW), FontStyle.Bold);
            label_Title.Font = new Font("等线", (float)(label_Title.Font.Size / PrmSW * SW), FontStyle.Bold);
            //------------------调整位置-----------------
            int SwitchWidthLoc = this.Width - btn_Switch.Size.Width;
            int SwitchHeightLoc = this.Height - btn_Switch.Size.Height;
            btn_Switch.Location = new Point(SwitchWidthLoc / 2, SwitchHeightLoc / 4);
            btn_Option.Location = new Point(SwitchWidthLoc / 2, SwitchHeightLoc / 2);
            btn_Help.Location = new Point(SwitchWidthLoc / 2, (SwitchHeightLoc / 4) * 3);
            btn_Small.Location = new Point(this.Width - btn_Small.Size.Width, 0);
            btn_Close.Location = new Point(this.Width - btn_Close.Size.Width, this.Height - btn_Small.Size.Height);
            label_Title.Location = new Point((this.Size.Width - label_Title.Size.Width) / 2, (this.Size.Height - label_Title.Size.Height) / 16);
            //------------------运行线程-----------------
            GetClipBD = new Thread(GetBoard);
            GetClipBD.SetApartmentState(ApartmentState.STA);
            GetClipBD.Start();
            Download = new Thread(Down);
            Download.Start();
            SummonNewWinTC.Start();
            //------------------检测自启动---------------
            if (!Program.RunInStartUp)
            {
                SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);//添加窗体阴影
            }
            else
            {
                this.Activated += Form1_Activated;
            }
            notifyIcon1.Visible = false;
            //------------------读取用户文件-------------
            CheckAppDate();//检测用户文件夹
            if (!File.Exists(CommonPath + @"\IsSetUp.xfe"))
            {
                if (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\XFE划词翻译.lnk"))
                {
                    CreateShortCut(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), string.Empty);
                    WriteIn(CommonPath + @"\IsSetUp.xfe", "TRSetUp");
                }
            }//是否初始化
            //----------------读取是否开机自启-----------
            if (File.Exists(CommonPath + @"\StartUp.xfe"))
            {
                StartUp = true;
            }
            else
            {
                StartUp = false;
            }
            //----------------检测是否更新状态-----------
            if (File.Exists(CommonPath + @"\ReWrite"))
            {
                if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\XFE划词翻译.lnk"))
                {
                    File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\XFE划词翻译.lnk");
                    CreateShortCut(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), string.Empty);
                }//重写桌面快捷方式
                if (File.Exists(CommonPath + @"\StartUp.xfe"))
                {
                    WindowsIdentity identity = WindowsIdentity.GetCurrent();
                    WindowsPrincipal principal = new WindowsPrincipal(identity);
                    if (principal.IsInRole(WindowsBuiltInRole.Administrator))
                    {
                        File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartup) + @"\XFE划词翻译.lnk");
                        CreateShortCut(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartup), "StartUp");
                        StartUp = true;
                    }
                    else
                    {
                        File.Delete(CommonPath + @"\StartUp.xfe");
                        StartUp = false;
                    }
                }
                else
                {
                    StartUp = false;
                }
                File.Delete(CommonPath + @"\ReWrite");
            }
            else
            {
                if (File.Exists(CommonPath + @"\GetAdmin"))
                {
                    WindowsIdentity identity = WindowsIdentity.GetCurrent();
                    WindowsPrincipal principal = new WindowsPrincipal(identity);
                    if (principal.IsInRole(WindowsBuiltInRole.Administrator))
                    {
                        if (File.Exists(CommonPath + @"\StartUp.xfe"))
                        {
                            File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartup) + @"\XFE划词翻译.lnk");
                            File.Delete(CommonPath + @"\StartUp.xfe");
                            File.Delete(CommonPath + @"\GetAdmin");
                            StartUp = false;
                        }
                        else
                        {
                            CreateShortCut(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartup), "StartUp");
                            WriteIn(CommonPath + @"\StartUp.xfe", "IsStartUp");
                            File.Delete(CommonPath + @"\GetAdmin");
                            StartUp = true;
                        }
                    }//检测是否获取到了管理员权限
                    else
                    {
                        File.Delete(CommonPath + @"\GetAdmin");
                        StartUp = false;
                    }
                }
            }
            if (ReadIn(CommonPath + @"\UserSelfEditData\Color", out Colorstring))
            {
                string[] ColorGroup = Colorstring.Split(new char[] { '|' });
                LineColor = BringStringToColor(ColorGroup[0]);
                TextColor = BringStringToColor(ColorGroup[1]);
                BGColor = BringStringToColor(ColorGroup[2]);
                if (ColorGroup.Length == 6)
                {
                    if (ColorGroup[3] == "0")
                    {
                        themeType = ThemeType.Light;
                    }
                    else if (ColorGroup[3] == "1")
                    {
                        themeType = ThemeType.Dark;
                    }
                    else
                    {
                        themeType = ThemeType.SelfEdit;
                    }
                    WinTCTextSize = float.Parse(ColorGroup[4]);
                    if (ColorGroup[5] == "false")
                    {
                        btn_Switch_Click(sender, e);
                    }
                }
                else
                {
                    WriteIn(CommonPath + @"\UserSelfEditData\Color", $"69,83,113|1,106,125|240,230,220|0|{WinTCTextSize}|{OutPutBoolInString(EnableFT)}");
                }
            }
            else
            {
                LineColor = Color.FromArgb(69, 83, 113);
                TextColor = Color.FromArgb(1, 106, 125);
                BGColor = Color.FromArgb(240, 230, 220);
                themeType = ThemeType.Light;
                WriteIn(CommonPath + @"\UserSelfEditData\Color", $"69,83,113|1,106,125|240,230,220|0|{WinTCTextSize}|{OutPutBoolInString(EnableFT)}");
            }
            //-----------------设置颜色------------------
            if (themeType == ThemeType.Dark)
            {
                ChangeButtonColor(Color.FromArgb(236, 230, 220), Color.FromArgb(69, 83, 113), Color.FromArgb(39, 53, 83), Color.FromArgb(59, 73, 103), Color.FromArgb(59, 73, 103));
                this.BackColor = Color.FromArgb(30, 30, 30);
                label_Title.ForeColor = Color.FromArgb(236, 230, 220);
            }
        }
        //-----------------拖动窗体----------------
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mouseLocation = new Point(-e.X, -e.Y);
                //表示鼠标当前位置相对于窗口左上角的坐标，
                //并取负数,这里的e是参数，
                //可以获取鼠标位置
                isDragging = true;//标识鼠标已经按下
            }
        }
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (isDragging)
            {
                Point newMouseLocation = MousePosition;
                //获取鼠标当前位置
                newMouseLocation.Offset(mouseLocation.X, mouseLocation.Y);
                //用鼠标当前位置加上鼠标相较于窗体左上角的
                //坐标的负数，也就获取到了新的窗体左上角位置
                if (sender is Form)
                {
                    Location = newMouseLocation;
                }

            }
        }
        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            if (isDragging)
            {
                isDragging = false;//鼠标已抬起，标识为false
            }
        }
        //-----------------加载窗体----------------
        private void Form1_Activated(object sender, EventArgs e)
        {
            btn_Small_Click(null, null);
            timerAddShadow.Start();
            this.Activated -= Form1_Activated;
        }
        private void GetBoard()
        {
            bool IfIsThisTimeRun = true;
            string StatueContent;
            ClipBoardConent = GetClipBoardContent();
            while (true)
            {
                //------------判断剪切板内容是否发生变化------------
                if (IfIsThisTimeRun)
                {
                    IfIsThisTimeRun = false;
                    if (ClipBoardConent != GetClipBoardContent() && GetClipBoardContent() != string.Empty)
                    {
                        ClipBoardConent = GetClipBoardContent();
                        if (EnableFT)
                        {
                            Isdifferent = true;
                        }
                    }
                }
                else
                {
                    IfIsThisTimeRun = true;
                }
                //------------判断用户是否又打开了此程序------------
                if (ReadIn(Application.UserAppDataPath + @"\Statue.xfe", out StatueContent))
                {
                    if (StatueContent == "1")
                    {
                        this.Invoke(new Action(() =>
                        {
                            this.Show();
                            this.Activate();
                        }));
                        notifyIcon1.Visible = false;
                        System.Media.SystemSounds.Exclamation.Play();
                        WriteIn(Application.UserAppDataPath + @"\Statue.xfe", "0");
                    }
                }
                //------------------------间隔----------------------
                Thread.Sleep(50);
            }
        }
        private void Down()
        {
            if (!File.Exists(CommonPath + @"\ReWrite"))
            {
                WebClientPro versionDow = new WebClientPro(10000);
                versionDow.DownloadFileCompleted += VersionDetected;
                versionDow.DownloadFileAsync(new Uri("https://www.xfegzs.com/XFETranslate/Version"), Application.UserAppDataPath + @"\version");
            }
        }
        private void VersionDetected(object sender, AsyncCompletedEventArgs e)
        {
            string versionAndPost = File.ReadAllText(Application.UserAppDataPath + @"\version");
            string version = versionAndPost.Split('$')[0];
            string Post = versionAndPost.Split('$')[1];
            if (version != Application.ProductVersion)
            {
                VersionTC(Post);
                this.Show();
                this.Activate();
                notifyIcon1.Visible = false;
            }
            File.Delete(Application.UserAppDataPath + @"\version");
        }
        public void VersionTC(string Text)
        {
            Panel pl = new Panel()
            {
                Size = new Size((int)(this.Size.Width / 1.5), (int)(this.Size.Height / 1.5)),
                BackColor = Color.FromArgb(240, 230, 220),
                ForeColor = Color.FromArgb(1, 106, 125),
            };
            Label lbltitle = new Label
            {
                Text = "发现新版本",
                ForeColor = Color.FromArgb(1, 106, 125),
                Font = SmallButtonTextFont,
                AutoSize = true,
            };
            lbltitle.Location = new Point((pl.Size.Width - lbltitle.Size.Width) / 2, (pl.Size.Height - lbltitle.Size.Height) / 16);
            Label lbl = new Label
            {
                Text = Text,
                AutoSize = true,
                ForeColor = Color.FromArgb(1, 106, 125),
                Font = SmallButtonTextFont,
                MaximumSize = new Size((pl.Size.Width - pl.Size.Width) / 8, 0)
            };
            lbl.Location = new Point((pl.Size.Width - lbl.Size.Width) / 16, (pl.Size.Height - lbl.Size.Height) / 5);
            Button button = new Button()
            {
                Text = "下载",
                BackColor = Color.Teal,
                Size = new Size(pl.Size.Width / 4, pl.Size.Height / 5),
                TextAlign = ContentAlignment.MiddleCenter,
                Font = SmallButtonTextFont,
                ForeColor = Color.FromArgb(240, 230, 220),
                FlatStyle = FlatStyle.Flat
            };
            button.Location = new Point((pl.Size.Width - button.Size.Width) / 6, (pl.Size.Height - button.Size.Height) - (pl.Size.Height - button.Size.Height) / 10);
            button.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 70, 95);
            button.FlatAppearance.MouseOverBackColor = Color.FromArgb(1, 106, 125);
            button.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
            button.FlatAppearance.BorderSize = 2;
            button.Click += btn_VersionTC_Click;
            Button button_Cancel = new Button()
            {
                Text = "取消",
                BackColor = Color.Teal,
                Size = new Size(pl.Size.Width / 4, pl.Size.Height / 5),
                TextAlign = ContentAlignment.MiddleCenter,
                Font = SmallButtonTextFont,
                ForeColor = Color.FromArgb(240, 230, 220),
                FlatStyle = FlatStyle.Flat
            };
            button_Cancel.Location = new Point((pl.Size.Width - button_Cancel.Size.Width) - (pl.Size.Width - button_Cancel.Size.Width) / 6, (pl.Size.Height - button_Cancel.Size.Height) - (pl.Size.Height - button_Cancel.Size.Height) / 10);
            button_Cancel.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 70, 95);
            button_Cancel.FlatAppearance.MouseOverBackColor = Color.FromArgb(1, 106, 125);
            button_Cancel.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
            button_Cancel.FlatAppearance.BorderSize = 2;
            button_Cancel.Click += btn_VersionTC_Cancel_Click;
            pl.Paint += VersionTC_Paint;
            this.Invoke(new Action(() =>
            {
                pl.Location = new Point((this.Size.Width - pl.Size.Width) / 2, (this.Size.Height - pl.Size.Height) / 2);
                this.Controls.Add(pl);
                pl.BringToFront();
                pl.Controls.Add(lbltitle);
                pl.Controls.Add(button);
                pl.Controls.Add(button_Cancel);
                pl.Controls.Add(lbl);
            }));
        }
        private void btn_VersionTC_Click(object sender, EventArgs e)
        {
            WebClientPro webClient = new WebClientPro(60000);
            webClient.DownloadFileCompleted += UpdateByCMD;
            webClient.DownloadFileAsync(new Uri("https://www.xfegzs.com/XFETranslate/TRapp"), Application.StartupPath + "\\XFETranslate_bin.exe");
            this.Controls.Remove((sender as Button).Parent);
        }
        private void btn_VersionTC_Cancel_Click(object sender, EventArgs e)
        {
            this.Controls.Remove((sender as Button).Parent);
        }
        private void UpdateByCMD(object sender, AsyncCompletedEventArgs e)
        {
            WriteIn(CommonPath + @"\ReWrite", "ReWrite");
            ProcessStartInfo psi;
            if (StartUp)
            {
                psi = new ProcessStartInfo("cmd.exe", $"/C Echo on & ping /n 2 127.0.0.1>nul & Del {Application.ExecutablePath} & Rename {Application.StartupPath}\\XFETranslate_bin.exe XFETranslate.exe & ping /n 2 127.0.0.1>nul & powershell -Command \"Start-Process 'XFETranslate.exe' -Verb runAs\"");
            }
            else
            {
                psi = new ProcessStartInfo("cmd.exe", $"/C Echo on & ping /n 2 127.0.0.1>nul & Del {Application.ExecutablePath} & Rename {Application.StartupPath}\\XFETranslate_bin.exe XFETranslate.exe & ping /n 2 127.0.0.1>nul & XFETranslate.exe");
            }
            psi.WindowStyle = ProcessWindowStyle.Hidden;
            psi.CreateNoWindow = true;
            Process.Start(psi);
            Application.Exit();
        }
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            GetClipBD.Abort();
            if (!timer2.Enabled)
            {
                timer2.Start();
            }
            WriteIn(CommonPath + @"\UserSelfEditData\Color", $"{BringColorToString(LineColor)},|{BringColorToString(TextColor)}|{BringColorToString(BGColor)}|{OutPutThemeColor(themeType)}|{WinTCTextSize}|{OutPutBoolInString(EnableFT)}");
            Application.Exit();
        }
        private void SummonNewWinTC_Tick(object sender, EventArgs e)
        {
            if (Isdifferent && EnableFT)
            {
                Isdifferent = false;
                string APPID = "20230214001562006";
                string DeCode = "XARI_HUduJ0WmMo4GSfH";
                string qury = ClipBoardConent;
                string salt = SummonLongRandomCode();
                string GETALL = $"{APPID}{qury}{salt}{DeCode}";
                string sign = GetMD5WithString(GETALL);
                string Url = $"https://fanyi-api.baidu.com/api/trans/vip/translate?q={qury}&from=en&to=zh&appid={APPID}&salt={salt}&sign={sign}";
                string result;
                HttpGet(Url, out result);
                string OutPut = ConvertUnicodeToUtf8(result);
                int a = 0;
                var DevGroup = OutPut.Split(new char[1] { '\"' });
                foreach (string Rex in DevGroup)
                {
                    if (Rex == "dst")
                    {
                        a += 2;
                        break;
                    }
                    else
                    {
                        a++;
                    }
                }
                if (a < DevGroup.Count() && a >= 0)
                {
                    MaxSize += (int)(DevGroup[a].Length / 1.5);
                }
                winTC = new WinTC()
                {
                    Name = ClipBoardConent
                };
                winTC.Show();
                Label label = winTC.Controls.Find("label", false)[0] as Label;
                winTC.Location = new Point(MousePosition.X - winTC.Width / 6, MousePosition.Y - winTC.Height / 6);
                winTC.Invoke(new Action(() =>
                {
                    if (a < DevGroup.Count() && a >= 0)
                    {
                        if (qury.Length <= 2000)
                        {
                            if (DevGroup[a].Length <= 1000)
                            {
                                label.Text = DevGroup[a];
                            }
                            else
                            {
                                label.Text = DevGroup[a];
                                MaxSize = 1400;
                            }
                            winTC.Size = new Size(label.Size.Width, label.Size.Height + 8);
                            label.Location = new Point((winTC.Width - label.Width) / 2, (winTC.Height - label.Height) / 2);
                        }
                        else
                        {
                            label.Text = "翻译文本长度超长，请点此查看详情";
                            winTC.Size = new Size(label.Size.Width, label.Size.Height + 8);
                            label.Location = new Point((winTC.Width - label.Width) / 2, (winTC.Height - label.Height) / 2);
                        }
                        int WinTCX = winTC.Location.X;
                        int WinTCY = winTC.Location.Y;
                        if (Cursor.Position.X + winTC.Width > SW)
                        {
                            winTC.Location = new Point(SW - winTC.Width - 10, WinTCY);
                        }
                        if(Cursor.Position.Y + winTC.Height > SH)
                        {
                            winTC.Location = new Point(WinTCX, SH - winTC.Width - 10);
                        }
                        //MessageBox.Show($"MX:{Cursor.Position.X}\nMY:{Cursor.Position.Y}\nWX:{winTC.Width}\nWY:{winTC.Height}\nSW:{SW}\nSH:{SH}");
                    }
                }));
                winTC.Activate();
            }
        }
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            if (sender is Form)
            {
                ControlPaint.DrawBorder(e.Graphics, (sender as Form).ClientRectangle,
                Color.FromArgb(69, 83, 113), 16, ButtonBorderStyle.Solid, //左边
                Color.FromArgb(69, 83, 113), 0, ButtonBorderStyle.Solid, //上边
                Color.FromArgb(69, 83, 113), 0, ButtonBorderStyle.Solid, //右边
                Color.FromArgb(69, 83, 113), 0, ButtonBorderStyle.Solid);//底边
            }
            else
            {
                ControlPaint.DrawBorder(e.Graphics, (sender as Panel).ClientRectangle,
                Color.FromArgb(69, 83, 113), 16, ButtonBorderStyle.Solid, //左边
                Color.FromArgb(69, 83, 113), 0, ButtonBorderStyle.Solid, //上边
                Color.FromArgb(69, 83, 113), 0, ButtonBorderStyle.Solid, //右边
                Color.FromArgb(69, 83, 113), 0, ButtonBorderStyle.Solid);//底边
            }
        }
        private void VersionTC_Paint(object sender, PaintEventArgs e)
        {
            ControlPaint.DrawBorder(e.Graphics, (sender as Panel).ClientRectangle,
            Color.FromArgb(69, 83, 113), 2, ButtonBorderStyle.Solid, //左边
            Color.FromArgb(69, 83, 113), 2, ButtonBorderStyle.Solid, //上边
            Color.FromArgb(69, 83, 113), 2, ButtonBorderStyle.Solid, //右边
            Color.FromArgb(69, 83, 113), 2, ButtonBorderStyle.Solid);//底边
        }
        private void label_Title_Paint(object sender, PaintEventArgs e)
        {
            if (themeType == ThemeType.Light || themeType == ThemeType.SelfEdit)
            {
                ControlPaint.DrawBorder(e.Graphics, (sender as Label).ClientRectangle,
                Color.FromArgb(69, 83, 113), 3, ButtonBorderStyle.Solid, //左边
                Color.FromArgb(69, 83, 113), 0, ButtonBorderStyle.Solid, //上边
                Color.FromArgb(69, 83, 113), 3, ButtonBorderStyle.Solid, //右边
                Color.FromArgb(69, 83, 113), 0, ButtonBorderStyle.Solid);//底边
            }
            else
            {
                ControlPaint.DrawBorder(e.Graphics, (sender as Label).ClientRectangle,
                Color.FromArgb(236, 230, 220), 3, ButtonBorderStyle.Solid, //左边
                Color.FromArgb(236, 230, 220), 0, ButtonBorderStyle.Solid, //上边
                Color.FromArgb(236, 230, 220), 3, ButtonBorderStyle.Solid, //右边
                Color.FromArgb(236, 230, 220), 0, ButtonBorderStyle.Solid);//底边
            }
        }
        private void btn_Close_Click(object sender, EventArgs e)
        {
            if (!timer2.Enabled)
            {
                timer2.Start();
            }
        }
        private void timer2_Tick(object sender, EventArgs e)
        {
            if (this.Opacity >= 0.025)
            {
                this.Opacity -= 0.025;
            }
            else
            {
                timer2.Stop();
                this.Close();
            }
        }
        private void btn_Small_Click(object sender, EventArgs e)
        {
            this.Hide();
            notifyIcon1.Visible = true;
        }
        private void btn_Switch_Click(object sender, EventArgs e)
        {
            if (EnableFT)
            {
                if (themeType == ThemeType.Light || themeType == ThemeType.SelfEdit)
                {
                    btn_Switch.Text = "开启划词翻译";
                    btn_Switch.BackColor = Color.FromArgb(205, 77, 77);
                    btn_Switch.FlatAppearance.MouseDownBackColor = Color.FromArgb(154, 16, 35);
                    btn_Switch.FlatAppearance.MouseOverBackColor = Color.FromArgb(184, 36, 55);
                    btn_Switch.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
                }
                else
                {
                    btn_Switch.Text = "开启划词翻译";
                    btn_Switch.BackColor = Color.FromArgb(40, 40, 40);
                    btn_Switch.FlatAppearance.MouseDownBackColor = Color.FromArgb(39, 53, 83);
                    btn_Switch.FlatAppearance.MouseOverBackColor = Color.FromArgb(50, 59, 73, 103);
                    btn_Switch.FlatAppearance.BorderColor = Color.FromArgb(59, 73, 103);
                }
                EnableFT = false;
            }
            else
            {
                if (themeType == ThemeType.Light || themeType == ThemeType.SelfEdit)
                {
                    btn_Switch.Text = "关闭划词翻译";
                    btn_Switch.BackColor = Color.Teal;
                    btn_Switch.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 70, 95);
                    btn_Switch.FlatAppearance.MouseOverBackColor = Color.FromArgb(1, 106, 125);
                    btn_Switch.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
                }
                else
                {
                    btn_Switch.Text = "关闭划词翻译";
                    btn_Switch.BackColor = Color.FromArgb(69, 83, 113);
                    btn_Switch.FlatAppearance.MouseDownBackColor = Color.FromArgb(39, 53, 83);
                    btn_Switch.FlatAppearance.MouseOverBackColor = Color.FromArgb(59, 73, 103);
                    btn_Switch.FlatAppearance.BorderColor = Color.FromArgb(59, 73, 103);
                }
                EnableFT = true;
            }
        }
        private void btn_SwitchColor_Click(object sender, EventArgs e)
        {
            //-------------普通控件重新着色--------------
            if (themeType == ThemeType.Light)
            {
                ChangeButtonColor(Color.FromArgb(236, 230, 220), Color.FromArgb(69, 83, 113), Color.FromArgb(39, 53, 83), Color.FromArgb(59, 73, 103), Color.FromArgb(59, 73, 103));
                ((sender as Button).Parent as Panel).BackColor = Color.FromArgb(30, 30, 30);
                //-----------------颜色按钮-----------------
                (sender as Button).Text = "深色主题";
                (sender as Button).ForeColor = Color.FromArgb(236, 230, 220);
                (sender as Button).BackColor = Color.FromArgb(69, 83, 113);
                (sender as Button).FlatAppearance.MouseDownBackColor = Color.FromArgb(39, 53, 83);
                (sender as Button).FlatAppearance.MouseOverBackColor = Color.FromArgb(59, 73, 103);
                (sender as Button).FlatAppearance.BorderColor = Color.FromArgb(59, 73, 103);
                //-----------------字体按钮-----------------
                btn_ChangeSize.ForeColor = Color.FromArgb(236, 230, 220);
                btn_ChangeSize.BackColor = Color.FromArgb(69, 83, 113);
                btn_ChangeSize.FlatAppearance.MouseDownBackColor = Color.FromArgb(39, 53, 83);
                btn_ChangeSize.FlatAppearance.MouseOverBackColor = Color.FromArgb(59, 73, 103);
                btn_ChangeSize.FlatAppearance.BorderColor = Color.FromArgb(59, 73, 103);
                //-----------------返回按钮-----------------
                btn_BackToMenu.ForeColor = Color.FromArgb(236, 230, 220);
                btn_BackToMenu.BackColor = Color.FromArgb(69, 83, 113);
                btn_BackToMenu.FlatAppearance.MouseDownBackColor = Color.FromArgb(39, 53, 83);
                btn_BackToMenu.FlatAppearance.MouseOverBackColor = Color.FromArgb(59, 73, 103);
                btn_BackToMenu.FlatAppearance.BorderColor = Color.FromArgb(59, 73, 103);
                //-----------------自启按钮-----------------
                btn_StartUp.ForeColor = Color.FromArgb(236, 230, 220);
                btn_StartUp.BackColor = Color.FromArgb(69, 83, 113);
                btn_StartUp.FlatAppearance.MouseDownBackColor = Color.FromArgb(39, 53, 83);
                btn_StartUp.FlatAppearance.MouseOverBackColor = Color.FromArgb(59, 73, 103);
                btn_StartUp.FlatAppearance.BorderColor = Color.FromArgb(59, 73, 103);
                //----------------更新主界面-----------------
                this.BackColor = Color.FromArgb(30, 30, 30);
                label_Title.ForeColor = Color.FromArgb(236, 230, 220);
                //-----------------设置变量-----------------
                themeType = ThemeType.Dark;
            }
            else if (themeType == ThemeType.Dark)
            {
                ChangeButtonColor(Color.FromArgb(236, 230, 220), Color.Teal, Color.FromArgb(0, 70, 95), Color.FromArgb(1, 106, 125), Color.FromArgb(69, 83, 113));
                ((sender as Button).Parent as Panel).BackColor = Color.FromArgb(236, 230, 220);
                //-----------------颜色按钮-----------------
                (sender as Button).Text = "自定义";
                (sender as Button).ForeColor = TextColor;
                (sender as Button).BackColor = BGColor;
                (sender as Button).FlatAppearance.MouseDownBackColor = Color.FromArgb(50, BGColor.R - BGColor.R / 3, BGColor.G - BGColor.G / 3, BGColor.B - BGColor.B / 3);
                (sender as Button).FlatAppearance.MouseOverBackColor = Color.FromArgb(20, BGColor.R - BGColor.R / 2, BGColor.G - BGColor.G / 2, BGColor.B - BGColor.B / 2);
                (sender as Button).FlatAppearance.BorderColor = LineColor;
                //-----------------字体按钮-----------------
                btn_ChangeSize.ForeColor = Color.FromArgb(236, 230, 220);
                btn_ChangeSize.BackColor = Color.Teal;
                btn_ChangeSize.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 70, 95);
                btn_ChangeSize.FlatAppearance.MouseOverBackColor = Color.FromArgb(1, 106, 125);
                btn_ChangeSize.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
                //-----------------返回按钮-----------------
                btn_BackToMenu.ForeColor = Color.FromArgb(236, 230, 220);
                btn_BackToMenu.BackColor = Color.Teal;
                btn_BackToMenu.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 70, 95);
                btn_BackToMenu.FlatAppearance.MouseOverBackColor = Color.FromArgb(1, 106, 125);
                btn_BackToMenu.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
                //-----------------返回按钮-----------------
                btn_StartUp.ForeColor = Color.FromArgb(236, 230, 220);
                btn_StartUp.BackColor = Color.Teal;
                btn_StartUp.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 70, 95);
                btn_StartUp.FlatAppearance.MouseOverBackColor = Color.FromArgb(1, 106, 125);
                btn_StartUp.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
                //--------------线条颜色按钮---------------
                btn_LineColor = new Button()
                {
                    Text = "线条颜色",
                    ForeColor = Color.FromArgb(255 - LineColor.R, 255 - LineColor.G, 255 - LineColor.B),
                    BackColor = LineColor,
                    FlatStyle = FlatStyle.Flat,
                    Font = SmallButtonTextFont,
                    TextAlign = ContentAlignment.MiddleCenter,
                    Size = new Size((int)(140 / PrmSW * SW), (int)(50 / PrmSW * SW)),
                    Location = new Point((((sender as Button).Parent as Panel).Size.Width - (int)(140 / PrmSW * SW)) / 5, (int)((((sender as Button).Parent as Panel).Size.Height - (int)(50 / PrmSW * SW)) / 4.1))
                };
                btn_LineColor.FlatAppearance.MouseDownBackColor = Color.FromArgb(180, LineColor.R - LineColor.R / 3, LineColor.G - LineColor.G / 3, LineColor.B - LineColor.B / 3);
                btn_LineColor.FlatAppearance.MouseOverBackColor = Color.FromArgb(100, LineColor.R - LineColor.R / 2, LineColor.G - LineColor.G / 2, LineColor.B - LineColor.B / 2);
                btn_LineColor.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
                btn_LineColor.FlatAppearance.BorderSize = 2;
                btn_LineColor.Click += btn_ChangeSelfColor_Click;
                ((sender as Button).Parent as Panel).Controls.Add(btn_LineColor);
                //--------------文字颜色按钮---------------
                btn_TextColor = new Button()
                {
                    Text = "文字颜色",
                    ForeColor = Color.FromArgb(255 - TextColor.R, 255 - TextColor.G, 255 - TextColor.B),
                    BackColor = TextColor,
                    FlatStyle = FlatStyle.Flat,
                    Font = SmallButtonTextFont,
                    TextAlign = ContentAlignment.MiddleCenter,
                    Size = new Size((int)(140 / PrmSW * SW), (int)(50 / PrmSW * SW)),
                    Location = new Point(((sender as Button).Parent as Panel).Size.Width - (int)(140 / PrmSW * SW) - (((sender as Button).Parent as Panel).Size.Width - (int)(140 / PrmSW * SW)) / 5, (int)((((sender as Button).Parent as Panel).Size.Height - (int)(50 / PrmSW * SW)) / 4.1))
                };
                btn_TextColor.FlatAppearance.MouseDownBackColor = Color.FromArgb(180, TextColor.R - TextColor.R / 3, TextColor.G - TextColor.G / 3, TextColor.B - TextColor.B / 3);
                btn_TextColor.FlatAppearance.MouseOverBackColor = Color.FromArgb(100, TextColor.R - TextColor.R / 2, TextColor.G - TextColor.G / 2, TextColor.B - TextColor.B / 2);
                btn_TextColor.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
                btn_TextColor.FlatAppearance.BorderSize = 2;
                btn_TextColor.Click += btn_ChangeSelfColor_Click;
                ((sender as Button).Parent as Panel).Controls.Add(btn_TextColor);
                //--------------背景颜色按钮---------------
                btn_BGColor = new Button()
                {
                    Text = "背景颜色",
                    ForeColor = Color.FromArgb(255 - BGColor.R, 255 - BGColor.G, 255 - BGColor.B),
                    BackColor = BGColor,
                    FlatStyle = FlatStyle.Flat,
                    Font = SmallButtonTextFont,
                    TextAlign = ContentAlignment.MiddleCenter,
                    Size = new Size((int)(180 / PrmSW * SW), (int)(50 / PrmSW * SW)),
                    Location = new Point((((sender as Button).Parent as Panel).Size.Width - (int)(180 / PrmSW * SW)) / 2, (int)((((sender as Button).Parent as Panel).Size.Height - (int)(50 / PrmSW * SW)) / 2.4))
                };
                btn_BGColor.FlatAppearance.MouseDownBackColor = Color.FromArgb(180, BGColor.R - BGColor.R / 3, BGColor.G - BGColor.G / 3, BGColor.B - BGColor.B / 3);
                btn_BGColor.FlatAppearance.MouseOverBackColor = Color.FromArgb(100, BGColor.R - BGColor.R / 2, BGColor.G - BGColor.G / 2, BGColor.B - BGColor.B / 2);
                btn_BGColor.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
                btn_BGColor.FlatAppearance.BorderSize = 2;
                btn_BGColor.Click += btn_ChangeSelfColor_Click;
                ((sender as Button).Parent as Panel).Controls.Add(btn_BGColor);
                //----------------更新主界面-----------------
                this.BackColor = Color.FromArgb(236, 230, 220);
                label_Title.ForeColor = Color.FromArgb(1, 106, 125);
                (sender as Button).Location = new Point((((sender as Button).Parent as Panel).Size.Width - (int)(340 / PrmSW * SW)) / 2, (((sender as Button).Parent as Panel).Size.Height - (int)(50 / PrmSW * SW)) / 16);
                btn_BackToMenu.Location = new Point((((sender as Button).Parent as Panel).Size.Width - (int)(340 / PrmSW * SW)) / 2, (((sender as Button).Parent as Panel).Size.Height - (int)(50 / PrmSW * SW)) - (((sender as Button).Parent as Panel).Size.Height - (int)(50 / PrmSW * SW)) / 16);
                btn_ChangeSize.Location = new Point((((sender as Button).Parent as Panel).Size.Width - (int)(340 / PrmSW * SW)) / 2, (((sender as Button).Parent as Panel).Size.Height - (int)(50 / PrmSW * SW)) - (int)((((sender as Button).Parent as Panel).Size.Height - (50 / PrmSW * SW)) / 2.4));
                btn_StartUp.Location = new Point((((sender as Button).Parent as Panel).Size.Width - (int)(340 / PrmSW * SW)) / 2, (((sender as Button).Parent as Panel).Size.Height - (int)(50 / PrmSW * SW)) - (int)((((sender as Button).Parent as Panel).Size.Height - (50 / PrmSW * SW)) / 4.2));
                //-----------------设置变量-----------------
                themeType = ThemeType.SelfEdit;
            }
            else
            {
                ChangeButtonColor(Color.FromArgb(236, 230, 220), Color.Teal, Color.FromArgb(0, 70, 95), Color.FromArgb(1, 106, 125), Color.FromArgb(69, 83, 113));
                ((sender as Button).Parent as Panel).BackColor = Color.FromArgb(236, 230, 220);
                //-----------------颜色按钮-----------------
                (sender as Button).Text = "浅色主题";
                (sender as Button).ForeColor = Color.FromArgb(236, 230, 220);
                (sender as Button).BackColor = Color.Teal;
                (sender as Button).FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 70, 95);
                (sender as Button).FlatAppearance.MouseOverBackColor = Color.FromArgb(1, 106, 125);
                (sender as Button).FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
                //-----------------字体按钮-----------------
                btn_ChangeSize.ForeColor = Color.FromArgb(236, 230, 220);
                btn_ChangeSize.BackColor = Color.Teal;
                btn_ChangeSize.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 70, 95);
                btn_ChangeSize.FlatAppearance.MouseOverBackColor = Color.FromArgb(1, 106, 125);
                btn_ChangeSize.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
                //-----------------返回按钮-----------------
                btn_BackToMenu.ForeColor = Color.FromArgb(236, 230, 220);
                btn_BackToMenu.BackColor = Color.Teal;
                btn_BackToMenu.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 70, 95);
                btn_BackToMenu.FlatAppearance.MouseOverBackColor = Color.FromArgb(1, 106, 125);
                btn_BackToMenu.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
                //-----------------返回按钮-----------------
                btn_StartUp.ForeColor = Color.FromArgb(236, 230, 220);
                btn_StartUp.BackColor = Color.Teal;
                btn_StartUp.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 70, 95);
                btn_StartUp.FlatAppearance.MouseOverBackColor = Color.FromArgb(1, 106, 125);
                btn_StartUp.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
                //----------------更新主界面-----------------
                this.BackColor = Color.FromArgb(236, 230, 220);
                label_Title.ForeColor = Color.FromArgb(1, 106, 125);
                (sender as Button).Location = new Point((((sender as Button).Parent as Panel).Size.Width - (int)(340 / PrmSW * SW)) / 2, (((sender as Button).Parent as Panel).Size.Height - (int)(50 / PrmSW * SW)) / 7);
                btn_BackToMenu.Location = new Point((((sender as Button).Parent as Panel).Size.Width - (int)(340 / PrmSW * SW)) / 2, (((sender as Button).Parent as Panel).Size.Height - (int)(50 / PrmSW * SW)) - (((sender as Button).Parent as Panel).Size.Height - (int)(50 / PrmSW * SW)) / 7);
                btn_ChangeSize.Location = new Point((((sender as Button).Parent as Panel).Size.Width - (int)(340 / PrmSW * SW)) / 2, (int)((((sender as Button).Parent as Panel).Size.Height - (50 / PrmSW * SW)) / 2.6));
                btn_StartUp.Location = new Point((((sender as Button).Parent as Panel).Size.Width - (int)(340 / PrmSW * SW)) / 2, ((sender as Button).Parent as Panel).Size.Height - (int)(50 / PrmSW * SW) - (int)((((sender as Button).Parent as Panel).Size.Height - (50 / PrmSW * SW)) / 2.6));
                ((sender as Button).Parent as Panel).Controls.Remove(btn_LineColor);
                ((sender as Button).Parent as Panel).Controls.Remove(btn_TextColor);
                ((sender as Button).Parent as Panel).Controls.Remove(btn_BGColor);
                //-----------------设置变量-----------------
                themeType = ThemeType.Light;
            }
            //------------切换开关特殊重着色-------------
            if (!EnableFT)
            {
                if (themeType == ThemeType.Light || themeType == ThemeType.SelfEdit)
                {
                    btn_Switch.Text = "开启划词翻译";
                    btn_Switch.BackColor = Color.FromArgb(205, 77, 77);
                    btn_Switch.FlatAppearance.MouseDownBackColor = Color.FromArgb(154, 16, 35);
                    btn_Switch.FlatAppearance.MouseOverBackColor = Color.FromArgb(184, 36, 55);
                    btn_Switch.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
                }
                else
                {
                    btn_Switch.Text = "开启划词翻译";
                    btn_Switch.BackColor = Color.FromArgb(40, 40, 40);
                    btn_Switch.FlatAppearance.MouseDownBackColor = Color.FromArgb(39, 53, 83);
                    btn_Switch.FlatAppearance.MouseOverBackColor = Color.FromArgb(50, 59, 73, 103);
                    btn_Switch.FlatAppearance.BorderColor = Color.FromArgb(59, 73, 103);
                }
            }
            else
            {
                if (themeType == ThemeType.Light || themeType == ThemeType.SelfEdit)
                {
                    btn_Switch.Text = "关闭划词翻译";
                    btn_Switch.BackColor = Color.Teal;
                    btn_Switch.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 70, 95);
                    btn_Switch.FlatAppearance.MouseOverBackColor = Color.FromArgb(1, 106, 125);
                    btn_Switch.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
                }
                else
                {
                    btn_Switch.Text = "关闭划词翻译";
                    btn_Switch.BackColor = Color.FromArgb(69, 83, 113);
                    btn_Switch.FlatAppearance.MouseDownBackColor = Color.FromArgb(39, 53, 83);
                    btn_Switch.FlatAppearance.MouseOverBackColor = Color.FromArgb(59, 73, 103);
                    btn_Switch.FlatAppearance.BorderColor = Color.FromArgb(59, 73, 103);
                }
            }
        }
        private void colorDialog1_HelpRequest(object sender, EventArgs e)
        {
            MessageBox.Show($"选择自定义你的{(sender as ColorDialog).Tag}颜色");
        }
        private void btn_BackToMenu_Click(object sender, EventArgs e)
        {
            WriteIn(CommonPath + @"\UserSelfEditData\Color", $"{BringColorToString(LineColor)},|{BringColorToString(TextColor)}|{BringColorToString(BGColor)}|{OutPutThemeColor(themeType)}|{WinTCTextSize}");
            ((sender as Button).Parent as Panel).Dispose();
        }
        private void btn_BackToMenuHelp_Click(object sender, EventArgs e)
        {
            ((sender as Button).Parent as Panel).Dispose();
        }
        private void btn_ChangeSelfColor_Click(object sender, EventArgs e)
        {
            colorDialog1.Tag = (sender as Button).Text;
            colorDialog1.HelpRequest += colorDialog1_HelpRequest;
            if ((sender as Button).Text == "线条颜色")
            {
                colorDialog1.Color = LineColor;
                colorDialog1.ShowDialog();
                LineColor = colorDialog1.Color;
                (sender as Button).ForeColor = Color.FromArgb(255 - LineColor.R, 255 - LineColor.G, 255 - LineColor.B);
                (sender as Button).BackColor = LineColor;
                (sender as Button).FlatAppearance.MouseDownBackColor = Color.FromArgb(180, LineColor.R - LineColor.R / 3, LineColor.G - LineColor.G / 3, LineColor.B - LineColor.B / 3);
                (sender as Button).FlatAppearance.MouseOverBackColor = Color.FromArgb(100, LineColor.R - LineColor.R / 2, LineColor.G - LineColor.G / 2, LineColor.B - LineColor.B / 2);
                btn_SwitchColor.FlatAppearance.BorderColor = LineColor;
            }
            else if ((sender as Button).Text == "文字颜色")
            {
                colorDialog1.Color = TextColor;
                colorDialog1.ShowDialog();
                TextColor = colorDialog1.Color;
                (sender as Button).ForeColor = Color.FromArgb(255 - TextColor.R, 255 - TextColor.G, 255 - TextColor.B);
                (sender as Button).BackColor = TextColor;
                (sender as Button).FlatAppearance.MouseDownBackColor = Color.FromArgb(180, TextColor.R - TextColor.R / 3, TextColor.G - TextColor.G / 3, TextColor.B - TextColor.B / 3);
                (sender as Button).FlatAppearance.MouseOverBackColor = Color.FromArgb(100, TextColor.R - TextColor.R / 2, TextColor.G - TextColor.G / 2, TextColor.B - TextColor.B / 2);
                btn_SwitchColor.ForeColor = TextColor;
            }
            else
            {
                colorDialog1.Color = BGColor;
                colorDialog1.ShowDialog();
                BGColor = colorDialog1.Color;
                (sender as Button).ForeColor = Color.FromArgb(255 - BGColor.R, 255 - BGColor.G, 255 - BGColor.B);
                (sender as Button).BackColor = BGColor;
                (sender as Button).FlatAppearance.MouseDownBackColor = Color.FromArgb(180, BGColor.R - BGColor.R / 3, BGColor.G - BGColor.G / 3, BGColor.B - BGColor.B / 3);
                (sender as Button).FlatAppearance.MouseOverBackColor = Color.FromArgb(100, BGColor.R - BGColor.R / 2, BGColor.G - BGColor.G / 2, BGColor.B - BGColor.B / 2);
                btn_SwitchColor.BackColor = BGColor;
            }
        }
        private void btn_ChangeSize_Click(object sender, EventArgs e)
        {
            if (WinTCTextSize == 7)
            {
                WinTCTextSize = 11;
                btn_ChangeSize.Text = "字体大小：小";
            }
            else if (WinTCTextSize == 11)
            {
                WinTCTextSize = 13;
                btn_ChangeSize.Text = "字体大小：中";
            }
            else if (WinTCTextSize == 13)
            {
                WinTCTextSize = 15;
                btn_ChangeSize.Text = "字体大小：大";
            }
            else if (WinTCTextSize == 15)
            {
                WinTCTextSize = 19;
                btn_ChangeSize.Text = "字体大小：超大";
            }
            else if (WinTCTextSize == 19)
            {
                WinTCTextSize = 7;
                btn_ChangeSize.Text = "字体大小：超小";
            }
        }
        private void btn_StartUp_Click(object sender, EventArgs e)
        {
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.FileName = Application.ExecutablePath;
            psi.Verb = "runas";
            try
            {
                WriteIn(CommonPath + @"\GetAdmin", "Getting...");
                Process.Start(psi);
                Application.Exit();
            }
            catch (Exception eee)
            {
                MessageBox.Show(eee.Message);
            }
        }
        private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Show();
                this.Activate();
                notifyIcon1.Visible = false;
            }
        }
        private void btn_Option_Click(object sender, EventArgs e)
        {
            //--------------Panel控件---------------
            Panel panel = new Panel()
            {
                Width = this.Size.Width - btn_Close.Width,
                Height = this.Size.Height,
                Location = new Point(0, 0),
                BackColor = Color.FromArgb(236, 230, 220),
            };
            panel.Paint += Form1_Paint;
            this.Controls.Add(panel);
            panel.BringToFront();
            //--------------主题按钮---------------
            btn_SwitchColor = new Button()
            {
                Text = "浅色主题",
                ForeColor = Color.FromArgb(236, 230, 220),
                BackColor = Color.Teal,
                FlatStyle = FlatStyle.Flat,
                Font = ButtonTextFont,
                Size = new Size((int)(340 / PrmSW * SW), (int)(50 / PrmSW * SW)),
                Location = new Point((panel.Size.Width - (int)(340 / PrmSW * SW)) / 2, (panel.Size.Height - (int)(50 / PrmSW * SW)) / 7)
            };
            btn_SwitchColor.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 70, 95);
            btn_SwitchColor.FlatAppearance.MouseOverBackColor = Color.FromArgb(1, 106, 125);
            btn_SwitchColor.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
            btn_SwitchColor.FlatAppearance.BorderSize = 2;
            btn_SwitchColor.Click += btn_SwitchColor_Click;
            panel.Controls.Add(btn_SwitchColor);
            //--------------返回按钮---------------
            btn_BackToMenu = new Button()
            {
                Text = "应用并返回",
                ForeColor = Color.FromArgb(236, 230, 220),
                BackColor = Color.Teal,
                FlatStyle = FlatStyle.Flat,
                Font = ButtonTextFont,
                Size = new Size((int)(340 / PrmSW * SW), (int)(50 / PrmSW * SW)),
                Location = new Point((panel.Size.Width - (int)(340 / PrmSW * SW)) / 2, (panel.Size.Height - (int)(50 / PrmSW * SW)) - (panel.Size.Height - (int)(50 / PrmSW * SW)) / 7)
            };
            btn_BackToMenu.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 70, 95);
            btn_BackToMenu.FlatAppearance.MouseOverBackColor = Color.FromArgb(1, 106, 125);
            btn_BackToMenu.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
            btn_BackToMenu.FlatAppearance.BorderSize = 2;
            btn_BackToMenu.Click += btn_BackToMenu_Click;
            panel.Controls.Add(btn_BackToMenu);
            //--------------字体按钮---------------
            btn_ChangeSize = new Button()
            {
                Text = "字体大小：中",
                ForeColor = Color.FromArgb(236, 230, 220),
                BackColor = Color.Teal,
                FlatStyle = FlatStyle.Flat,
                Font = ButtonTextFont,
                Size = new Size((int)(340 / PrmSW * SW), (int)(50 / PrmSW * SW)),
                Location = new Point((panel.Size.Width - (int)(340 / PrmSW * SW)) / 2, (int)((panel.Size.Height - (50 / PrmSW * SW)) / 2.6))
            };
            btn_ChangeSize.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 70, 95);
            btn_ChangeSize.FlatAppearance.MouseOverBackColor = Color.FromArgb(1, 106, 125);
            btn_ChangeSize.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
            btn_ChangeSize.FlatAppearance.BorderSize = 2;
            btn_ChangeSize.Click += btn_ChangeSize_Click;
            panel.Controls.Add(btn_ChangeSize);
            //--------------自启按钮---------------
            btn_StartUp = new Button()
            {
                Text = "开机自启已关闭",
                ForeColor = Color.FromArgb(236, 230, 220),
                BackColor = Color.Teal,
                FlatStyle = FlatStyle.Flat,
                Font = ButtonTextFont,
                Size = new Size((int)(340 / PrmSW * SW), (int)(50 / PrmSW * SW)),
                Location = new Point((panel.Size.Width - (int)(340 / PrmSW * SW)) / 2, panel.Size.Height - (int)(50 / PrmSW * SW) - (int)((panel.Size.Height - (50 / PrmSW * SW)) / 2.6))
            };
            btn_StartUp.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 70, 95);
            btn_StartUp.FlatAppearance.MouseOverBackColor = Color.FromArgb(1, 106, 125);
            btn_StartUp.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
            btn_StartUp.FlatAppearance.BorderSize = 2;
            btn_StartUp.Click += btn_StartUp_Click;
            panel.Controls.Add(btn_StartUp);
            //--------------检测主题---------------
            if (themeType == ThemeType.Dark)
            {
                panel.BackColor = Color.FromArgb(30, 30, 30);
                //--------------主题按钮---------------
                btn_SwitchColor.Text = "深色主题";
                btn_SwitchColor.ForeColor = Color.FromArgb(236, 230, 220);
                btn_SwitchColor.BackColor = Color.FromArgb(69, 83, 113);
                btn_SwitchColor.FlatAppearance.MouseDownBackColor = Color.FromArgb(39, 53, 83);
                btn_SwitchColor.FlatAppearance.MouseOverBackColor = Color.FromArgb(59, 73, 103);
                btn_SwitchColor.FlatAppearance.BorderColor = Color.FromArgb(59, 73, 103);
                //--------------返回按钮---------------
                btn_BackToMenu.ForeColor = Color.FromArgb(236, 230, 220);
                btn_BackToMenu.BackColor = Color.FromArgb(69, 83, 113);
                btn_BackToMenu.FlatAppearance.MouseDownBackColor = Color.FromArgb(39, 53, 83);
                btn_BackToMenu.FlatAppearance.MouseOverBackColor = Color.FromArgb(59, 73, 103);
                btn_BackToMenu.FlatAppearance.BorderColor = Color.FromArgb(59, 73, 103);
                //--------------字体按钮---------------
                btn_ChangeSize.ForeColor = Color.FromArgb(236, 230, 220);
                btn_ChangeSize.BackColor = Color.FromArgb(69, 83, 113);
                btn_ChangeSize.FlatAppearance.MouseDownBackColor = Color.FromArgb(39, 53, 83);
                btn_ChangeSize.FlatAppearance.MouseOverBackColor = Color.FromArgb(59, 73, 103);
                btn_ChangeSize.FlatAppearance.BorderColor = Color.FromArgb(59, 73, 103);
                //--------------自启按钮---------------
                btn_StartUp.ForeColor = Color.FromArgb(236, 230, 220);
                btn_StartUp.BackColor = Color.FromArgb(69, 83, 113);
                btn_StartUp.FlatAppearance.MouseDownBackColor = Color.FromArgb(39, 53, 83);
                btn_StartUp.FlatAppearance.MouseOverBackColor = Color.FromArgb(59, 73, 103);
                btn_StartUp.FlatAppearance.BorderColor = Color.FromArgb(59, 73, 103);
            }
            else if (themeType == ThemeType.SelfEdit)
            {
                btn_SwitchColor.Text = "自定义";
                btn_SwitchColor.ForeColor = TextColor;
                btn_SwitchColor.BackColor = BGColor;
                btn_SwitchColor.FlatAppearance.MouseDownBackColor = Color.FromArgb(50, BGColor.R - BGColor.R / 3, BGColor.G - BGColor.G / 3, BGColor.B - BGColor.B / 3);
                btn_SwitchColor.FlatAppearance.MouseOverBackColor = Color.FromArgb(20, BGColor.R - BGColor.R / 2, BGColor.G - BGColor.G / 2, BGColor.B - BGColor.B / 2);
                btn_SwitchColor.FlatAppearance.BorderColor = LineColor;
                //--------------线条颜色按钮---------------
                btn_LineColor = new Button()
                {
                    Text = "线条颜色",
                    ForeColor = Color.FromArgb(255 - LineColor.R, 255 - LineColor.G, 255 - LineColor.B),
                    BackColor = LineColor,
                    FlatStyle = FlatStyle.Flat,
                    Font = SmallButtonTextFont,
                    TextAlign = ContentAlignment.MiddleCenter,
                    Size = new Size((int)(140 / PrmSW * SW), (int)(50 / PrmSW * SW)),
                    Location = new Point((panel.Size.Width - (int)(140 / PrmSW * SW)) / 5, (int)((panel.Size.Height - (int)(50 / PrmSW * SW)) / 4.1))
                };
                btn_LineColor.FlatAppearance.MouseDownBackColor = Color.FromArgb(180, LineColor.R - LineColor.R / 3, LineColor.G - LineColor.G / 3, LineColor.B - LineColor.B / 3);
                btn_LineColor.FlatAppearance.MouseOverBackColor = Color.FromArgb(100, LineColor.R - LineColor.R / 2, LineColor.G - LineColor.G / 2, LineColor.B - LineColor.B / 2);
                btn_LineColor.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
                btn_LineColor.FlatAppearance.BorderSize = 2;
                btn_LineColor.Click += btn_ChangeSelfColor_Click;
                panel.Controls.Add(btn_LineColor);
                //--------------文字颜色按钮---------------
                btn_TextColor = new Button()
                {
                    Text = "文字颜色",
                    ForeColor = Color.FromArgb(255 - TextColor.R, 255 - TextColor.G, 255 - TextColor.B),
                    BackColor = TextColor,
                    FlatStyle = FlatStyle.Flat,
                    Font = SmallButtonTextFont,
                    TextAlign = ContentAlignment.MiddleCenter,
                    Size = new Size((int)(140 / PrmSW * SW), (int)(50 / PrmSW * SW)),
                    Location = new Point(panel.Size.Width - (int)(140 / PrmSW * SW) - (panel.Size.Width - (int)(140 / PrmSW * SW)) / 5, (int)((panel.Size.Height - (int)(50 / PrmSW * SW)) / 4.1))
                };
                btn_TextColor.FlatAppearance.MouseDownBackColor = Color.FromArgb(180, TextColor.R - TextColor.R / 3, TextColor.G - TextColor.G / 3, TextColor.B - TextColor.B / 3);
                btn_TextColor.FlatAppearance.MouseOverBackColor = Color.FromArgb(100, TextColor.R - TextColor.R / 2, TextColor.G - TextColor.G / 2, TextColor.B - TextColor.B / 2);
                btn_TextColor.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
                btn_TextColor.FlatAppearance.BorderSize = 2;
                btn_TextColor.Click += btn_ChangeSelfColor_Click;
                panel.Controls.Add(btn_TextColor);
                //--------------背景颜色按钮---------------
                btn_BGColor = new Button()
                {
                    Text = "背景颜色",
                    ForeColor = Color.FromArgb(255 - BGColor.R, 255 - BGColor.G, 255 - BGColor.B),
                    BackColor = BGColor,
                    FlatStyle = FlatStyle.Flat,
                    Font = SmallButtonTextFont,
                    TextAlign = ContentAlignment.MiddleCenter,
                    Size = new Size((int)(180 / PrmSW * SW), (int)(50 / PrmSW * SW)),
                    Location = new Point((panel.Size.Width - (int)(180 / PrmSW * SW)) / 2, (int)((panel.Size.Height - (int)(50 / PrmSW * SW)) / 2.4))
                };
                btn_BGColor.FlatAppearance.MouseDownBackColor = Color.FromArgb(180, BGColor.R - BGColor.R / 3, BGColor.G - BGColor.G / 3, BGColor.B - BGColor.B / 3);
                btn_BGColor.FlatAppearance.MouseOverBackColor = Color.FromArgb(100, BGColor.R - BGColor.R / 2, BGColor.G - BGColor.G / 2, BGColor.B - BGColor.B / 2);
                btn_BGColor.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
                btn_BGColor.FlatAppearance.BorderSize = 2;
                btn_BGColor.Click += btn_ChangeSelfColor_Click;
                panel.Controls.Add(btn_BGColor);
                //--------------调整控件位置---------------
                btn_SwitchColor.Location = new Point((panel.Size.Width - (int)(340 / PrmSW * SW)) / 2, (panel.Size.Height - (int)(50 / PrmSW * SW)) / 16);
                btn_BackToMenu.Location = new Point((panel.Size.Width - (int)(340 / PrmSW * SW)) / 2, (panel.Size.Height - (int)(50 / PrmSW * SW)) - (panel.Size.Height - (int)(50 / PrmSW * SW)) / 16);
                btn_ChangeSize.Location = new Point((panel.Size.Width - (int)(340 / PrmSW * SW)) / 2, (panel.Size.Height - (int)(50 / PrmSW * SW)) - (int)((panel.Size.Height - (50 / PrmSW * SW)) / 2.4));
                btn_StartUp.Location = new Point((panel.Size.Width - (int)(340 / PrmSW * SW)) / 2, (panel.Size.Height - (int)(50 / PrmSW * SW)) - (int)((panel.Size.Height - (50 / PrmSW * SW)) / 4.2));
            }
            //--------------检测字体---------------
            if (WinTCTextSize == 7)
            {
                btn_ChangeSize.Text = "字体大小：超小";
            }
            else if (WinTCTextSize == 11)
            {
                btn_ChangeSize.Text = "字体大小：小";
            }
            else if (WinTCTextSize == 13)
            {
                btn_ChangeSize.Text = "字体大小：中";
            }
            else if (WinTCTextSize == 15)
            {
                btn_ChangeSize.Text = "字体大小：大";
            }
            else if (WinTCTextSize == 19)
            {
                btn_ChangeSize.Text = "字体大小：超大";
            }
            //--------------检测自启---------------
            if (StartUp)
            {
                btn_StartUp.Text = "开机自启已开启";
            }
        }
        private void btn_HelpLabel_LinkClick(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start(@"http://xfegzs.com/TRsp.mp4");
        }
        private void btn_Help_Click(object sender, EventArgs e)
        {
            Panel panel = new Panel()
            {
                Width = this.Size.Width - btn_Close.Width,
                Height = this.Size.Height,
                Location = new Point(0, 0),
                BackColor = Color.FromArgb(236, 230, 220),
            };
            panel.Paint += Form1_Paint;
            this.Controls.Add(panel);
            panel.BringToFront();
            //--------------说明标签---------------
            LinkLabel HelpLabel = new LinkLabel()
            {
                Text = "如何使用：在需要翻译的地方划线，接着按Ctrl+C即可弹出翻译后的内容（请确保主菜单界面的开关按钮为开启状态）。点击翻译框即可跳转至百度翻译的详细界面，查看读音和详细释义~\n如若还有不懂的可以点此观看教学视频",
                LinkBehavior = LinkBehavior.HoverUnderline,
                LinkColor = Color.FromArgb(80, 80, 80),
                ActiveLinkColor = Color.FromArgb(60, 60, 60),
                Font = SmallButtonTextFont,
                ForeColor = Color.FromArgb(1, 106, 125),
                AutoSize = true,
                Location = new Point(16, 3),
                MaximumSize = new Size(panel.Size.Width - 16, 0)
            };
            HelpLabel.LinkArea = new LinkArea() { Start = HelpLabel.Text.Length - 8, Length = 8 };
            HelpLabel.LinkClicked += btn_HelpLabel_LinkClick;
            panel.Controls.Add(HelpLabel);
            //--------------返回按钮---------------
            Button btn_BackToMenuHelp = new Button()
            {
                Text = "返回主界面",
                ForeColor = Color.FromArgb(236, 230, 220),
                BackColor = Color.Teal,
                FlatStyle = FlatStyle.Flat,
                Font = ButtonTextFont,
                Size = new Size((int)(340 / PrmSW * SW), (int)(50 / PrmSW * SW)),
                Location = new Point((panel.Size.Width - (int)(340 / PrmSW * SW)) / 2, (panel.Size.Height - (int)(50 / PrmSW * SW)) - (panel.Size.Height - (int)(50 / PrmSW * SW)) / 16)
            };
            btn_BackToMenuHelp.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 70, 95);
            btn_BackToMenuHelp.FlatAppearance.MouseOverBackColor = Color.FromArgb(1, 106, 125);
            btn_BackToMenuHelp.FlatAppearance.BorderColor = Color.FromArgb(69, 83, 113);
            btn_BackToMenuHelp.FlatAppearance.BorderSize = 2;
            btn_BackToMenuHelp.Click += btn_BackToMenuHelp_Click;
            panel.Controls.Add(btn_BackToMenuHelp);
            //--------------打赏图片---------------
            Panel WeChatGetImagePanel = new Panel()
            {
                Size = new Size((int)(panel.Size.Height / 2.5), (int)(panel.Size.Height / 2.5)),
                BackgroundImage = Resources.WeChat,
                BackgroundImageLayout = ImageLayout.Stretch
            };
            WeChatGetImagePanel.Location = new Point((panel.Size.Width - WeChatGetImagePanel.Size.Width) / 2, panel.Size.Height - WeChatGetImagePanel.Size.Height - (panel.Size.Height - WeChatGetImagePanel.Size.Height) / 3);
            panel.Controls.Add(WeChatGetImagePanel);
            //-------------检测并设置主题-------------
            if (themeType == ThemeType.Dark)
            {
                panel.BackColor = Color.FromArgb(30, 30, 30);
                HelpLabel.LinkColor = Color.FromArgb(220, 220, 220);
                HelpLabel.ActiveLinkColor = Color.FromArgb(100, 100, 100);
                HelpLabel.ForeColor = Color.FromArgb(240, 230, 220);
                btn_BackToMenuHelp.ForeColor = Color.FromArgb(236, 230, 220);
                btn_BackToMenuHelp.BackColor = Color.FromArgb(69, 83, 113);
                btn_BackToMenuHelp.FlatAppearance.MouseDownBackColor = Color.FromArgb(39, 53, 83);
                btn_BackToMenuHelp.FlatAppearance.MouseOverBackColor = Color.FromArgb(59, 73, 103);
                btn_BackToMenuHelp.FlatAppearance.BorderColor = Color.FromArgb(59, 73, 103);
            }
        }
        private void timerAddShadow_Tick(object sender, EventArgs e)
        {
            SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);//添加窗体阴影
            timerAddShadow.Dispose();
        }
        //------------------调用阴影DLL------------------
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int GetClassLong(IntPtr hwnd, int nIndex);
        //------------------调用阴影DLL------------------
    }
    public class WebClientPro : WebClient
    {
        /// <summary>
        /// 过期时间
        /// </summary>
        public int Timeout { get; set; }

        public WebClientPro(int timeout = 10000)
        {
            Timeout = timeout;
        }

        /// <summary>
        /// 重写GetWebRequest,添加WebRequest对象超时时间
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        protected override WebRequest GetWebRequest(Uri address)
        {
            HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
            request.Timeout = Timeout;
            request.ReadWriteTimeout = Timeout;
            return request;
        }
    }
}
