diff --git a/Netch.sln b/Netch.sln index d912721b..815eb2b1 100644 --- a/Netch.sln +++ b/Netch.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 16.0.29009.5 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Netch", "Netch\Netch.csproj", "{4B041B91-5790-4571-8C58-C63FFE4BC9F8}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SearchComboBox", "SearchComboBox\SearchComboBox.csproj", "{A8715AF4-ACC6-43F9-9381-4294C5360623}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTest", "UnitTest\UnitTest.csproj", "{53397641-35CA-4336-8E22-2CE12EF476AC}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interop.nfapinet", "Interop.nfapinet\Interop.nfapinet.csproj", "{2C968ADF-4822-46A9-A7D9-D05A61CB14DE}" @@ -21,10 +19,6 @@ Global {4B041B91-5790-4571-8C58-C63FFE4BC9F8}.Debug|x64.Build.0 = Debug|x64 {4B041B91-5790-4571-8C58-C63FFE4BC9F8}.Release|x64.ActiveCfg = Release|x64 {4B041B91-5790-4571-8C58-C63FFE4BC9F8}.Release|x64.Build.0 = Release|x64 - {A8715AF4-ACC6-43F9-9381-4294C5360623}.Debug|x64.ActiveCfg = Debug|Any CPU - {A8715AF4-ACC6-43F9-9381-4294C5360623}.Debug|x64.Build.0 = Debug|Any CPU - {A8715AF4-ACC6-43F9-9381-4294C5360623}.Release|x64.ActiveCfg = Release|Any CPU - {A8715AF4-ACC6-43F9-9381-4294C5360623}.Release|x64.Build.0 = Release|Any CPU {53397641-35CA-4336-8E22-2CE12EF476AC}.Debug|x64.ActiveCfg = Debug|x64 {53397641-35CA-4336-8E22-2CE12EF476AC}.Debug|x64.Build.0 = Debug|x64 {53397641-35CA-4336-8E22-2CE12EF476AC}.Release|x64.ActiveCfg = Release|x64 diff --git a/Netch/Forms/MainForm.Designer.cs b/Netch/Forms/MainForm.Designer.cs index bfdd9411..f92028f5 100644 --- a/Netch/Forms/MainForm.Designer.cs +++ b/Netch/Forms/MainForm.Designer.cs @@ -56,7 +56,7 @@ this.ModeLabel = new System.Windows.Forms.Label(); this.ServerLabel = new System.Windows.Forms.Label(); this.ProfileNameText = new System.Windows.Forms.TextBox(); - this.ModeComboBox = new System.Windows.Forms.SearchComboBox(); + this.ModeComboBox = new System.Windows.Forms.ComboBox(); this.ServerComboBox = new System.Windows.Forms.ComboBox(); this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); this.EditServerPictureBox = new System.Windows.Forms.PictureBox(); @@ -371,9 +371,9 @@ // // 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.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.ModeComboBox.FormattingEnabled = true; this.ModeComboBox.IntegralHeight = false; this.ModeComboBox.Location = new System.Drawing.Point(54, 33); @@ -752,7 +752,7 @@ private System.Windows.Forms.ToolStripMenuItem ImportServersFromClipboardToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem ManageSubscribeLinksToolStripMenuItem; private System.Windows.Forms.MenuStrip MenuStrip; - private System.Windows.Forms.SearchComboBox ModeComboBox; + private System.Windows.Forms.ComboBox ModeComboBox; private System.Windows.Forms.Label ModeLabel; private System.Windows.Forms.ToolStripMenuItem ModeToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem HelpToolStripMenuItem; diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs index 63e7ef01..8639646f 100644 --- a/Netch/Forms/MainForm.cs +++ b/Netch/Forms/MainForm.cs @@ -49,18 +49,6 @@ namespace Netch.Forms // 监听电源事件 SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; - ModeComboBox.KeyUp += (_, args) => - { - switch (args.KeyData) - { - case Keys.Escape: - { - SelectLastMode(); - return; - } - } - }; - CheckForIllegalCrossThreadCalls = false; } @@ -525,9 +513,6 @@ namespace Netch.Forms return; } - // 清除模式搜索框文本选择 - ModeComboBox.Select(0, 0); - State = State.Starting; try @@ -875,7 +860,6 @@ namespace Netch.Forms private void ActiveProfile(Profile profile) { ProfileNameText.Text = profile.ProfileName; - ModeComboBox.ResetCompletionList(); var server = ServerComboBox.Items.Cast().FirstOrDefault(s => s.Remark.Equals(profile.ServerRemark)); var mode = ModeComboBox.Items.Cast().FirstOrDefault(m => m.Remark.Equals(profile.ModeRemark)); diff --git a/Netch/Netch.csproj b/Netch/Netch.csproj index 1b483784..1bd11f07 100644 --- a/Netch/Netch.csproj +++ b/Netch/Netch.csproj @@ -77,7 +77,6 @@ - diff --git a/SearchComboBox/Properties/AssemblyInfo.cs b/SearchComboBox/Properties/AssemblyInfo.cs deleted file mode 100644 index 6e7c125c..00000000 --- a/SearchComboBox/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("SearchComboBox")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("SearchComboBox")] -[assembly: AssemblyCopyright("Copyright © 2020")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("a8715af4-acc6-43f9-9381-4294c5360623")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SearchComboBox/SearchComboBox.cs b/SearchComboBox/SearchComboBox.cs deleted file mode 100644 index aa7a435f..00000000 --- a/SearchComboBox/SearchComboBox.cs +++ /dev/null @@ -1,179 +0,0 @@ -using System.Linq; - -namespace System.Windows.Forms -{ - [System.ComponentModel.DesignerCategory(@"Code")] - public class SearchComboBox : ComboBox - { - public SearchComboBox() - { - AutoCompleteMode = AutoCompleteMode.Suggest; - } - - - private string prevKeyword; - - private string Keyword - { - get => _keyword; - set - { - prevKeyword = _keyword; - if (value == null) - { - _keyword = null; - return; - } - - if (_keyword == value) - { - return; - } - - _keyword = value; - ReevaluateCompletionList(); - } - } - - protected override void OnTextChanged(EventArgs e) - { - try - { - if (string.IsNullOrEmpty(Text)) - { - if (!IsOriginalItems) - ResetCompletionList(); - Keyword = null; - } - else - { - if (AutoFillTag.All(o => o.ToString() != Text)) - { - Keyword = Text; - } - } - } - finally - { - base.OnTextChanged(e); - } - } - - - private object[] AutoFillTag - { - get - { - if (Tag == null) - { - Tag = Items.Cast().ToArray(); - } - - return (object[]) Tag; - } - } - - private bool IsOriginalItems => Items.Count == AutoFillTag.Length; - - public void ResetCompletionList() - { - Keyword = null; - try - { - SuspendLayout(); - - if (IsOriginalItems) - return; - - Items.Clear(); - Items.AddRange(AutoFillTag); - } - finally - { - ResumeLayout(true); - } - } - - private static int findFirstDifIndex(string s1, string s2) - { - for (var i = 0; i < Math.Min(s1.Length, s2.Length); i++) - if (s1[i] != s2[i]) - return i; - - return -1; - } - - private object[] _newList; - private string _keyword; - - private void ReevaluateCompletionList() - { - SuspendLayout(); - var keyword = Keyword.ToLowerInvariant().Trim(); - - var selectionStart = SelectionStart; - if (selectionStart == Text.Length) - { - selectionStart = -1; - } - else - { - selectionStart = findFirstDifIndex(prevKeyword, Keyword); - } - - try - { - var originalList = AutoFillTag; - if (originalList == null) - { - Tag = originalList = Items.Cast().ToArray(); - } - - if (string.IsNullOrEmpty(Keyword)) - { - ResetCompletionList(); - return; - } - else - { - _newList = originalList.Where(x => x.ToString().ToLowerInvariant().Contains(keyword)).ToArray(); - } - - if (_newList.Any()) - { - Items.Clear(); - Items.AddRange(_newList.ToArray()); - - if (!DroppedDown) - { - DroppedDown = true; - } - else - { - // TODO 预期下拉框高度变长则重新打开下拉框 - } - - Cursor.Current = Cursors.Default; - } - else - { - DroppedDown = false; - Items.Clear(); - } - - if (selectionStart == -1) - { - Select(Text.Length, 0); - } - else - { - Select(selectionStart + 1, 0); - } - } - finally - { - ResumeLayout(true); - } - } - } -} \ No newline at end of file diff --git a/SearchComboBox/SearchComboBox.csproj b/SearchComboBox/SearchComboBox.csproj deleted file mode 100644 index 0832ddae..00000000 --- a/SearchComboBox/SearchComboBox.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - net5.0-windows7 - false - AnyCPU - true - latest - - - - none - false - - - - - - - - \ No newline at end of file