From 7e9875a096fda9ffc06415569f2e68058852ae42 Mon Sep 17 00:00:00 2001 From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com> Date: Fri, 19 Feb 2021 17:33:07 +0800 Subject: [PATCH] Rename NetchLib to SearchComboBox --- Netch.sln | 72 ++-- Netch/Netch.csproj | 2 +- NetchLib/.gitignore | 3 - SearchComboBox/.gitignore | 3 + .../Properties/AssemblyInfo.cs | 72 ++-- .../SearchComboBox.cs | 356 +++++++++--------- .../SearchComboBox.csproj | 2 +- 7 files changed, 255 insertions(+), 255 deletions(-) delete mode 100644 NetchLib/.gitignore create mode 100644 SearchComboBox/.gitignore rename {NetchLib => SearchComboBox}/Properties/AssemblyInfo.cs (91%) rename {NetchLib => SearchComboBox}/SearchComboBox.cs (96%) rename NetchLib/NetchLib.csproj => SearchComboBox/SearchComboBox.csproj (88%) diff --git a/Netch.sln b/Netch.sln index 12a0de1a..da67cd3c 100644 --- a/Netch.sln +++ b/Netch.sln @@ -1,36 +1,36 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -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}") = "NetchLib", "NetchLib\NetchLib.csproj", "{A8715AF4-ACC6-43F9-9381-4294C5360623}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "Test\Test.csproj", "{53397641-35CA-4336-8E22-2CE12EF476AC}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4B041B91-5790-4571-8C58-C63FFE4BC9F8}.Debug|x64.ActiveCfg = Debug|x64 - {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|x64 - {A8715AF4-ACC6-43F9-9381-4294C5360623}.Debug|x64.Build.0 = Debug|x64 - {A8715AF4-ACC6-43F9-9381-4294C5360623}.Release|x64.ActiveCfg = Release|x64 - {A8715AF4-ACC6-43F9-9381-4294C5360623}.Release|x64.Build.0 = Release|x64 - {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 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {6EC9B043-ACA5-4BB9-96DB-493A2EF6E43F} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +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}") = "Test", "Test\Test.csproj", "{53397641-35CA-4336-8E22-2CE12EF476AC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4B041B91-5790-4571-8C58-C63FFE4BC9F8}.Debug|x64.ActiveCfg = Debug|x64 + {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 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6EC9B043-ACA5-4BB9-96DB-493A2EF6E43F} + EndGlobalSection +EndGlobal diff --git a/Netch/Netch.csproj b/Netch/Netch.csproj index 1710a5ac..e9610be0 100644 --- a/Netch/Netch.csproj +++ b/Netch/Netch.csproj @@ -53,7 +53,7 @@ - + diff --git a/NetchLib/.gitignore b/NetchLib/.gitignore deleted file mode 100644 index d2ee16f1..00000000 --- a/NetchLib/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/bin -/obj -/NetchLib.csproj.user \ No newline at end of file diff --git a/SearchComboBox/.gitignore b/SearchComboBox/.gitignore new file mode 100644 index 00000000..bc53ad0c --- /dev/null +++ b/SearchComboBox/.gitignore @@ -0,0 +1,3 @@ +/bin +/obj +/SearchComboBox.csproj.user \ No newline at end of file diff --git a/NetchLib/Properties/AssemblyInfo.cs b/SearchComboBox/Properties/AssemblyInfo.cs similarity index 91% rename from NetchLib/Properties/AssemblyInfo.cs rename to SearchComboBox/Properties/AssemblyInfo.cs index 7a3124ff..6e7c125c 100644 --- a/NetchLib/Properties/AssemblyInfo.cs +++ b/SearchComboBox/Properties/AssemblyInfo.cs @@ -1,36 +1,36 @@ -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("NetchLib")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("NetchLib")] -[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")] +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/NetchLib/SearchComboBox.cs b/SearchComboBox/SearchComboBox.cs similarity index 96% rename from NetchLib/SearchComboBox.cs rename to SearchComboBox/SearchComboBox.cs index 9a76bad3..aa7a435f 100644 --- a/NetchLib/SearchComboBox.cs +++ b/SearchComboBox/SearchComboBox.cs @@ -1,179 +1,179 @@ -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); - } - } - } +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/NetchLib/NetchLib.csproj b/SearchComboBox/SearchComboBox.csproj similarity index 88% rename from NetchLib/NetchLib.csproj rename to SearchComboBox/SearchComboBox.csproj index e80b948f..38bf84d5 100644 --- a/NetchLib/NetchLib.csproj +++ b/SearchComboBox/SearchComboBox.csproj @@ -3,7 +3,7 @@ net48 false - x64 + AnyCPU true latest