From b20c4ec564afd23073fa3d872e43406d24315414 Mon Sep 17 00:00:00 2001 From: DengYq Date: Fri, 13 Sep 2019 12:39:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E5=B1=80=E6=A8=A1=E5=BC=8F=E4=B8=8B?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E6=89=98=E7=9B=98=E5=8F=98=E4=B8=BA=E7=B2=89?= =?UTF-8?q?=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- v2rayN/v2rayN/Forms/BaseForm.cs | 34 +++++++++++++++++++++++++++++++++ v2rayN/v2rayN/Forms/MainForm.cs | 15 +++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/v2rayN/v2rayN/Forms/BaseForm.cs b/v2rayN/v2rayN/Forms/BaseForm.cs index 9d8f9b0e..a315b8b2 100644 --- a/v2rayN/v2rayN/Forms/BaseForm.cs +++ b/v2rayN/v2rayN/Forms/BaseForm.cs @@ -8,11 +8,13 @@ namespace v2rayN.Forms { protected static Config config; protected static System.Drawing.Icon icon; + protected static System.Drawing.Icon globleAgentIcon; public BaseForm() { InitializeComponent(); LoadCustomIcon(); + LoadGlobleAgentCustomIcon(); } private void LoadCustomIcon() @@ -35,5 +37,37 @@ namespace v2rayN.Forms Utils.SaveLog($"Loading custom icon failed: {e.Message}"); } } + + //设置托盘图标 + private void LoadGlobleAgentCustomIcon() + { + if (this.Icon == null) + { + globleAgentIcon = this.Icon; + } + + //原图标进行颜色变化 + System.Drawing.Bitmap gImage = this.Icon.ToBitmap(); + for (int x = 0; x < gImage.Width; x++) + { + for (int y = 0; y < gImage.Height; y++) + { + System.Drawing.Color pixelColor = gImage.GetPixel(x, y); + + if ((0 == pixelColor.R + && 0 == pixelColor.G + && 0 == pixelColor.B) + || (253 == pixelColor.R + && 253 == pixelColor.G + && 253 == pixelColor.B)) + { + continue; + } + //粉色 + gImage.SetPixel(x, y, System.Drawing.Color.FromArgb(255, 174, 210)); + } + } + globleAgentIcon = System.Drawing.Icon.FromHandle(gImage.GetHicon()); + } } } diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index 6cd61fe0..2dab724d 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -385,6 +385,17 @@ namespace v2rayN.Forms toolSslPacPort.Text = $"{HttpProxyHandle.GetPacUrl()}"; } } + + //设置托盘图标 + if (config.sysAgentEnabled && 1 == config.listenerType) + { + this.notifyMain.Icon = globleAgentIcon; + } + else + { + this.notifyMain.Icon = this.Icon; + } + } private void ssMain_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { @@ -1010,12 +1021,12 @@ namespace v2rayN.Forms private void HideForm() { - //this.WindowState = FormWindowState.Minimized; this.Hide(); - this.notifyMain.Icon = this.Icon; + this.notifyMain.Visible = true; this.ShowInTaskbar = false; + SetVisibleCore(false); }