/// <summary> /// 执行初始化操作 /// </summary> private void Init() { trayMenuHsiAlgorithmGeometry.Tag = HsiAlgorithm.Geometry; trayMenuHsiAlgorithmAxis.Tag = HsiAlgorithm.Axis; trayMenuHsiAlgorithmSegment.Tag = HsiAlgorithm.Segment; trayMenuHsiAlgorithmBajon.Tag = HsiAlgorithm.Bajon; trayMenuHsiAlgorithmStandard.Tag = HsiAlgorithm.Standard; previewForm = new PreviewForm(); previewForm.LocationChanged += previewForm_LocationChanged; currentDisplayMode = DisplayMode.Fixed; SwitchHsiAlgorithm(Settings.Main.HsiAlgorithm); colorBuffer = new StringBuilder(8, 64); if (Settings.Preview.Visible) { TogglePreview(); } if (trayMenuFixed.Checked) { FixedPosition(); } SwitchFormatMode(Settings.Main.Format); var now = DateTime.Now; lastPressTime = Util.Enum <HotKeyType>() .ToDictionary(item => item, item => now); HotKey.Bind(Handle); trayMenuCopyPolicyHexValueOnly.Checked = Settings.Base.HexValueOnly; trayMenuCopyPolicyRgbValueOnly.Checked = Settings.Base.RgbValueOnly; trayMenuCopyPolicyUpperCase.Checked = Settings.Base.CopyUpperCase; new Thread(() => { UpdateTooltip(); // 读取开机启动的注册表 this.InvokeMethod(() => { trayMenuAutoStart.Checked = Settings.Base.Autostart; trayMenuAutoPin.Checked = Settings.Base.AutoPin; trayMenuPixelScale.Checked = Settings.Preview.PixelScale; }); }) { IsBackground = true }.Start(); caretTimer = new Timer { Interval = caretInterval }; caretTimer.Tick += carettimer_Tick; caretTimer.Start(); colorTimer = new Timer { Interval = colorInterval }; colorTimer.Tick += colortimer_Tick; colorTimer.Start(); // 检查是否是首次运行 if (Settings.Base.IsFirstRun) { Settings.Base.IsFirstRun = false; // 首次运行时,打开帮助窗口 trayMenuShowAbout_Click(null, null); if (!IsDisposed) { // 然后打开快捷键设置窗口 trayMenuHotkey_Click(null, null); } } // 是否监听剪贴板 trayMenuEnableClipboard.Checked = Settings.Clipboard.Enabled; if (trayMenuEnableClipboard.Checked) { NativeMethods.AddClipboardFormatListener(Handle); } // 加载语言并选中使用的项 new Thread(() => { // 当前显示的语言 var locale = (Settings.I18n.Lang ?? System.Globalization.CultureInfo.InstalledUICulture.Name).ToLower(); // 加载自定义语言 var langs = i18n.I18nManager.GetLocalLangs(); if (langs.Any()) { // 都放到其它语言菜单项下 var others = new ToolStripMenuItem(); resources.ApplyResources(others, "trayMenuLanguageOther"); others.Name = "trayMenuLanguageOther"; // 存放语言 tooltip 的临时量 var temp = new StringBuilder(); var subs = langs.Select(language => { var item = new ToolStripMenuItem(); item.Name = $"customize-lang--{language.Locale}"; item.Text = language.Name; // 选中项 var l = language.Locale.ToLower(); item.Checked = locale == l || locale.StartsWith(l) || l.StartsWith(locale); // 提示信息中显示语言的版本以及作者 temp.Append($"{language.Version}\n"); if (language.Authors != null && language.Authors.Any()) { temp.Append("------------\n"); foreach (var author in language.Authors) { temp.AppendFormat("{0}/{1}\n", author.Name, author.Mail); if (string.IsNullOrEmpty(author.HomePage)) { temp.Append(author.HomePage); } } } item.ToolTipText = temp.ToString(); temp.Clear(); return(item); }); // 添加菜单项 others.DropDownItems.AddRange(subs.ToArray()); this.InvokeMethod(() => { trayMenuLanguage.DropDownItems.Add(others); }); } if (locale.StartsWith("zh")) { trayMenuLanguageZH.Checked = true; } else if (!langs.Any() || locale.StartsWith("en")) { // 没有其它语言或设置为英语时 trayMenuLanguageEN.Checked = true; } }) { IsBackground = true }.Start(); // 启动时检查更新 trayMenuCheckUpdateOnStartup.Checked = Settings.Update.CheckOnStartup; // 自动检查更新 if (trayMenuCheckUpdateOnStartup.Checked && (DateTime.Now.Date - Settings.Update.LastUpdate).TotalDays >= Settings.Update.Span) { update.UpdateForm.ShowWindow(true); } }
/// <summary> /// 执行初始化操作 /// </summary> private void Init() { trayMenuHsiAlgorithmGeometry.Tag = HsiAlgorithm.Geometry; trayMenuHsiAlgorithmAxis.Tag = HsiAlgorithm.Axis; trayMenuHsiAlgorithmSegment.Tag = HsiAlgorithm.Segment; trayMenuHsiAlgorithmBajon.Tag = HsiAlgorithm.Bajon; trayMenuHsiAlgorithmStandard.Tag = HsiAlgorithm.Standard; previewForm = new PreviewForm(); previewForm.LocationChanged += previewForm_LocationChanged; currentDisplayMode = DisplayMode.Fixed; SwitchHsiAlgorithm(Settings.Main.HsiAlgorithm); colorBuffer = new StringBuilder(8, 64); if (Settings.Preview.Visible) { TogglePreview(); } if (trayMenuFixed.Checked) { FixedPosition(); } SwitchFormatMode(Settings.Main.Format); var now = DateTime.Now; lastPressTime = Util.Enum <HotKeyType>() .ToDictionary(item => item, item => now); HotKey.Bind(Handle); trayMenuCopyPolicyHexValueOnly.Checked = Settings.Base.HexValueOnly; trayMenuCopyPolicyRgbValueOnly.Checked = Settings.Base.RgbValueOnly; new Thread(() => { UpdateTooltip(); // 读取开机启动的注册表 trayMenuAutoStart.Checked = Settings.Base.Autostart; trayMenuAutoPin.Checked = Settings.Base.AutoPin; trayMenuPixelScale.Checked = Settings.Preview.PixelScale; }) { IsBackground = true }.Start(); caretTimer = new Timer { Interval = caretInterval }; caretTimer.Tick += carettimer_Tick; caretTimer.Start(); colorTimer = new Timer { Interval = colorInterval }; colorTimer.Tick += colortimer_Tick; colorTimer.Start(); // 检查是否是首次运行 if (Settings.Base.IsFirstRun) { Settings.Base.IsFirstRun = false; // 首次运行时,打开帮助窗口 trayMenuShowHelp_Click(null, null); if (!IsDisposed) { // 然后打开快捷键设置窗口 trayMenuHotkey_Click(null, null); } } // 启动时检查更新 trayMenuCheckUpdateOnStartup.Checked = Settings.Update.CheckOnStartup; // 自动检查更新 if (trayMenuCheckUpdateOnStartup.Checked && (DateTime.Now.Date - Settings.Update.LastUpdate).TotalDays >= Settings.Update.Span) { UpdateForm.ShowWindow(true); } }
/// <summary> /// 画放大图,每个方向各取5个像素 /// </summary> private void DrawPreview(Point pt) { var size = previewForm.Height / 11; // 目标:预览窗口越大,放大倍数越大 // preview 预览窗口大小/11得到的数字 // size 取色宽度 // 做法:从屏幕上取到的大小不按线性变化,预览窗口放大两次,取色宽度才放大一次 // 例: // 预览窗口大小 相对放大倍数 取色宽度 实际放大倍数 // preview=121 => 11 => size = 11 - (11 - 11) / 2 = 11 => scale = 121/11 = 11 // preview=132 => 12 => size = 12 - (12 - 11) / 2 = 11 => scale = 132/11 = 12 // preview=143 => 13 => size = 13 - (13 - 11) / 2 = 12 => scale = 143/12 = 11.92 // preview=154 => 14 => size = 14 - (14 - 11) / 2 = 13 => scale = 154/13 = 11.85 // preview=165 => 15 => size = 15 - (15 - 11) / 2 = 13 => scale = 165/13 = 12.69 // preview=176 => 16 => size = 16 - (16 - 11) / 2 = 14 => scale = 176/14 = 12.57 // preview=187 => 17 => size = 17 - (17 - 11) / 2 = 14 => scale = 187/14 = 13.36 // preview=198 => 18 => size = 18 - (18 - 11) / 2 = 15 => scale = 198/15 = 13.2 // preview=209 => 19 => size = 19 - (19 - 11) / 2 = 15 => scale = 209/15 = 13.93 // preview=220 => 20 => size = 20 - (20 - 11) / 2 = 16 => scale = 220/16 = 13.75 // preview=231 => 21 => size = 21 - (21 - 11) / 2 = 16 => scale = 231/16 = 14.44 size -= (size - 11) / 2; if (size % 2 == 0) { size += 1; } var pic = new Bitmap(size, size); // 从中心点到左侧和顶部的距离 var extend = size / 2; var graphics = Graphics.FromImage(pic); try { graphics.CopyFromScreen(pt.X - extend, pt.Y - extend, 0, 0, pic.Size); } catch (Win32Exception) { // ignore the exception // System.ComponentModel.Win32Exception (0x80004005): 句柄无效。 } graphics.Save(); try { previewForm.UpdateImage(pic); } catch (Exception) { try { if (previewForm != null && !previewForm.IsDisposed) { previewForm.Dispose(); } } catch (Exception) { // ignore } // 重试一次 previewForm = new PreviewForm(); previewForm.UpdateImage(pic); } }
/// <summary> /// 执行初始化操作 /// </summary> private void Init() { // 接收消息 Msg.Listen(); previewForm = new PreviewForm(); previewForm.LocationChanged += previewForm_LocationChanged; currentDisplayMode = DisplayMode.Fixed; colorBuffer = new StringBuilder(8, 64); if (Settings.Preview.Visible) { TogglePreview(); } if (Settings.Main.Display == DisplayMode.Fixed) { FixedPosition(); } SwitchFormatMode(Settings.Main.Format); var now = DateTime.Now; lastPressTime = Util.Enum <HotKeyType>() .ToDictionary(item => item, item => now); HotKey.Bind(Handle); new Thread(() => { UpdateTooltip(); }) { IsBackground = true }.Start(); caretTimer = new Timer { Interval = caretInterval }; caretTimer.Tick += carettimer_Tick; caretTimer.Start(); colorTimer = new Timer { Interval = colorInterval }; colorTimer.Tick += colortimer_Tick; colorTimer.Start(); // 是否监听剪贴板 if (Settings.Clipboard.Enabled) { NativeMethods.AddClipboardFormatListener(Handle); } // 加载语言并选中使用的项 //new Thread(() => //{ // // 当前显示的语言 // var locale = (Settings.I18n.Lang ?? System.Globalization.CultureInfo.InstalledUICulture.Name).ToLower(); // // 加载自定义语言 // var langs = i18n.I18nManager.GetLocalLangs(); // if (langs.Any()) // { // // 都放到其它语言菜单项下 // var others = new ToolStripMenuItem(); // resources.ApplyResources(others, "trayMenuLanguageOther"); // others.Name = "trayMenuLanguageOther"; // // 存放语言 tooltip 的临时量 // var temp = new StringBuilder(); // var subs = langs.Select(language => // { // var item = new ToolStripMenuItem(); // item.Name = $"customize-lang--{language.Locale}"; // item.Text = language.Name; // // 选中项 // var l = language.Locale.ToLower(); // item.Checked = locale == l || locale.StartsWith(l) || l.StartsWith(locale); // // 提示信息中显示语言的版本以及作者 // temp.Append($"{language.Version}\n"); // if (language.Authors != null && language.Authors.Any()) // { // temp.Append("------------\n"); // foreach (var author in language.Authors) // { // temp.AppendFormat("{0}/{1}\n", author.Name, author.Mail); // if (string.IsNullOrEmpty(author.HomePage)) // { // temp.Append(author.HomePage); // } // } // } // item.ToolTipText = temp.ToString(); // temp.Clear(); // return item; // }); // // 添加菜单项 // others.DropDownItems.AddRange(subs.ToArray()); // this.InvokeMethod(() => // { // trayMenuLanguage.DropDownItems.Add(others); // }); // } // if (locale.StartsWith("zh")) // { // trayMenuLanguageZH.Checked = true; // } // else if (!langs.Any() || locale.StartsWith("en")) // { // // 没有其它语言或设置为英语时 // trayMenuLanguageEN.Checked = true; // } //}) //{ // IsBackground = true //}.Start(); DoFirstRunWorks(); // 自动检查更新 if (Settings.Update.CheckOnStartup && (DateTime.Now.Date - Settings.Update.LastUpdate).TotalDays >= Settings.Update.Interval) { update.UpdateForm.ShowWindow(true); } //RegisterDeskband(); var worker = new System.ComponentModel.BackgroundWorker(); worker.DoWork += AppArgsHandler; worker.RunWorkerAsync(); // 启动 websocket if (Settings.Websocket.Enabled) { new HttpServer("127.0.0.1", Settings.Websocket.Port).Start(); } }