diff --git a/Netch/Forms/MainForm.Designer.cs b/Netch/Forms/MainForm.Designer.cs index 6e35dc0b..0a551854 100644 --- a/Netch/Forms/MainForm.Designer.cs +++ b/Netch/Forms/MainForm.Designer.cs @@ -81,13 +81,13 @@ namespace Netch.Forms this.SettingsButton = new System.Windows.Forms.Button(); this.ProfileGroupBox = new System.Windows.Forms.GroupBox(); this.ProfileTable = new System.Windows.Forms.TableLayoutPanel(); + this.ModeComboBox = new System.Windows.Forms.SearchComboBox(); this.EditPictureBox = new System.Windows.Forms.PictureBox(); this.CopyLinkPictureBox = new System.Windows.Forms.PictureBox(); this.DeletePictureBox = new System.Windows.Forms.PictureBox(); this.SpeedPictureBox = new System.Windows.Forms.PictureBox(); this.EditModePictureBox = new System.Windows.Forms.PictureBox(); this.DeleteModePictureBox = new System.Windows.Forms.PictureBox(); - this.ModeComboBox = new System.Windows.Forms.SearchComboBox(); this.MenuStrip.SuspendLayout(); this.ConfigurationGroupBox.SuspendLayout(); this.configLayoutPanel.SuspendLayout(); @@ -343,7 +343,7 @@ namespace Netch.Forms // this.configLayoutPanel.ColumnCount = 3; this.configLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); - this.configLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.configLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.configLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.configLayoutPanel.Controls.Add(this.ProfileLabel, 0, 2); this.configLayoutPanel.Controls.Add(this.ModeLabel, 0, 1); @@ -577,6 +577,19 @@ namespace Netch.Forms this.ProfileTable.Size = new System.Drawing.Size(703, 43); this.ProfileTable.TabIndex = 0; // + // ModeComboBox + // + this.ModeComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; + this.ModeComboBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.ModeComboBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed; + this.ModeComboBox.FormattingEnabled = true; + this.ModeComboBox.IntegralHeight = false; + this.ModeComboBox.Location = new System.Drawing.Point(54, 34); + this.ModeComboBox.Name = "ModeComboBox"; + this.ModeComboBox.Size = new System.Drawing.Size(546, 24); + this.ModeComboBox.TabIndex = 2; + this.ModeComboBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ComboBox_DrawItem); + // // EditPictureBox // this.EditPictureBox.Cursor = System.Windows.Forms.Cursors.Hand; @@ -645,19 +658,6 @@ namespace Netch.Forms this.DeleteModePictureBox.TabStop = false; this.DeleteModePictureBox.Click += new System.EventHandler(this.DeleteModePictureBox_Click); // - // ModeComboBox - // - this.ModeComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; - this.ModeComboBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.ModeComboBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed; - this.ModeComboBox.FormattingEnabled = true; - this.ModeComboBox.IntegralHeight = false; - this.ModeComboBox.Location = new System.Drawing.Point(54, 34); - this.ModeComboBox.Name = "ModeComboBox"; - this.ModeComboBox.Size = new System.Drawing.Size(546, 24); - this.ModeComboBox.TabIndex = 2; - this.ModeComboBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ComboBox_DrawItem); - // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); @@ -679,6 +679,7 @@ namespace Netch.Forms this.Text = "Netch"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing); this.Load += new System.EventHandler(this.MainForm_Load); + this.VisibleChanged += new System.EventHandler(this.MainForm_VisibleChanged); this.MenuStrip.ResumeLayout(false); this.MenuStrip.PerformLayout(); this.ConfigurationGroupBox.ResumeLayout(false); diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs index 9cc1ea26..a285f94e 100644 --- a/Netch/Forms/MainForm.cs +++ b/Netch/Forms/MainForm.cs @@ -48,6 +48,7 @@ namespace Netch.Forms /// public static MainForm Instance = null; + public MainForm() { InitializeComponent(); @@ -384,6 +385,10 @@ namespace Netch.Forms ExitToolStripButton.Text = Utils.i18N.Translate(ExitToolStripButton.Text); RelyToolStripMenuItem.Text = Utils.i18N.Translate(RelyToolStripMenuItem.Text); + SizeHeight = Size.Height; + ControllHeight = ConfigurationGroupBox.Controls[0].Height/3; + ProfileBoxHeight = ProfileGroupBox.Height; + CFGBoxHeight = ConfigurationGroupBox.Height; InitProfile(); // 自动检测延迟 @@ -1232,48 +1237,64 @@ namespace Netch.Forms } + // init at MainFrom_Load() + private int SizeHeight; + private int ControllHeight; + private int ProfileBoxHeight; + private int CFGBoxHeight; + + public void InitProfile() { - var num_profile = Global.Settings.ProfileCount; - if (num_profile == 0) + + foreach (var button in ProfileButtons) { - ProfileGroupBox.Size = new Size(0, 0); - ConfigurationGroupBox.Size -= new Size(0, 25); - this.Size -= new Size(0, 70 + 25); + button.Dispose(); + } + ProfileButtons.Clear(); + ProfileTable.ColumnStyles.Clear(); + ProfileTable.RowStyles.Clear(); + + var numProfile = Global.Settings.ProfileCount; + if (numProfile == 0) + { + configLayoutPanel.RowStyles[2].SizeType = SizeType.Percent; configLayoutPanel.RowStyles[2].Height = 0; + ProfileGroupBox.Visible = false; + + ConfigurationGroupBox.Size = new Size(ConfigurationGroupBox.Size.Width, CFGBoxHeight-ControllHeight); + Size = new Size(Size.Width,SizeHeight-(ControllHeight+ProfileBoxHeight)); + return; } - ProfileTable.ColumnCount = num_profile; + configLayoutPanel.RowStyles[2].SizeType = SizeType.AutoSize; + ProfileGroupBox.Visible = true; + ConfigurationGroupBox.Size = new Size(ConfigurationGroupBox.Size.Width,CFGBoxHeight); + Size = new Size(Size.Width,SizeHeight); - while (Global.Settings.profiles.Count < num_profile) + + ProfileTable.ColumnCount = numProfile; + + while (Global.Settings.Profiles.Count < numProfile) { - Global.Settings.profiles.Add(new Models.Profile()); + Global.Settings.Profiles.Add(new Models.Profile()); } // buttons - for (var i = 0; i < num_profile; ++i) + for (var i = 0; i < numProfile; ++i) { var b = new Button(); ProfileTable.Controls.Add(b, i, 0); b.Location = new Point(i * 100, 0); b.Click += ProfileButton_Click; b.Dock = DockStyle.Fill; - b.Text = "None"; - ProfileButtons.Add(b); + b.Text = !Global.Settings.Profiles[i].IsDummy ? Global.Settings.Profiles[i].ProfileName : Utils.i18N.Translate("None"); - if (!Global.Settings.profiles[i].IsDummy) - { - b.Text = Global.Settings.profiles[i].ProfileName; - } - else - { - b.Text = Utils.i18N.Translate(b.Text); - } + ProfileButtons.Add(b); } // equal column - ProfileTable.ColumnStyles.Clear(); for (var i = 1; i <= ProfileTable.RowCount; i++) { ProfileTable.RowStyles.Add(new RowStyle(SizeType.Percent, 1)); @@ -1286,7 +1307,7 @@ namespace Netch.Forms private string LoadProfile(int index) { - var p = Global.Settings.profiles[index]; + var p = Global.Settings.Profiles[index]; if (p.IsDummy) throw new Exception("Profile not found."); @@ -1329,7 +1350,7 @@ namespace Netch.Forms var selectedMode = (Models.Mode)ModeComboBox.SelectedItem; var name = ProfileNameText.Text; - Global.Settings.profiles[index] = new Models.Profile(selectedServer, selectedMode, name); + Global.Settings.Profiles[index] = new Models.Profile(selectedServer, selectedMode, name); } @@ -1568,5 +1589,14 @@ namespace Netch.Forms { Process.Start($"https://mega.nz/file/9OQ1EazJ#0pjJ3xt57AVLr29vYEEv15GSACtXVQOGlEOPpi_2Ico"); } + + private void MainForm_VisibleChanged(object sender, EventArgs e) + { + if (!Visible) + return; + + InitProfile(); + + } } } diff --git a/Netch/Forms/SettingForm.Designer.cs b/Netch/Forms/SettingForm.Designer.cs index 0af2b4a3..5cdba74b 100644 --- a/Netch/Forms/SettingForm.Designer.cs +++ b/Netch/Forms/SettingForm.Designer.cs @@ -473,9 +473,9 @@ // // ProfileCount_TextBox // - this.ProfileCount_TextBox.Location = new System.Drawing.Point(209, 164); + this.ProfileCount_TextBox.Location = new System.Drawing.Point(120, 164); this.ProfileCount_TextBox.Name = "ProfileCount_TextBox"; - this.ProfileCount_TextBox.Size = new System.Drawing.Size(226, 23); + this.ProfileCount_TextBox.Size = new System.Drawing.Size(90, 23); this.ProfileCount_TextBox.TabIndex = 9; this.ProfileCount_TextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // diff --git a/Netch/Forms/SettingForm.cs b/Netch/Forms/SettingForm.cs index 3c4fb4c8..34e45f5e 100644 --- a/Netch/Forms/SettingForm.cs +++ b/Netch/Forms/SettingForm.cs @@ -433,7 +433,7 @@ namespace Netch.Forms Global.Settings.TUNTAP.UseFakeDNS = UseFakeDNSCheckBox.Checked; Utils.Configuration.Save(); - MessageBox.Show(Utils.i18N.Translate("Saved. Modify some settings need to restart the software"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show(Utils.i18N.Translate("Saved"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } } diff --git a/Netch/Models/Setting.cs b/Netch/Models/Setting.cs index 7c0491ad..10806750 100644 --- a/Netch/Models/Setting.cs +++ b/Netch/Models/Setting.cs @@ -142,7 +142,7 @@ namespace Netch.Models /// /// 已保存的快捷配置 /// - public List profiles = new List(); + public List Profiles = new List(); /// /// 快捷配置数量 diff --git a/Netch/Resources/zh-CN b/Netch/Resources/zh-CN index 49bb99e4..db88ef9f 100644 --- a/Netch/Resources/zh-CN +++ b/Netch/Resources/zh-CN @@ -165,7 +165,7 @@ "Port value illegal. Try again.": "端口值非法。请重试。", "Check update when opened": "打开软件时检查更新", "Start Shadowsocks from DLL (No support for ACL)": "SS DLL(推荐使用,不支持 ACL)", - "ProfileCount": "快捷配置数量(重启软件生效)", + "ProfileCount": "快捷配置数量", "ProfileCount value illegal. Try again.": "快捷配置数值非法。请重试。", "STUN_ServerPort value illegal. Try again.": "STUN 端口数值非法。请重试。", "Detection interval value illegal. Try again.": "检测间隔值非法。请重试。", @@ -179,7 +179,7 @@ "STUN Server Port": "STUN 服务器端口", "Custom ACL": "自定义 ACL 规则", "Language": "语言", - "Saved. Modify some settings need to restart the software": "保存成功,修改部分设置需重启软件", + "Saved.": "保存成功", "Profile": "配置名", "Profiles": "配置",