mirror of
https://github.com/netchx/netch.git
synced 2026-03-18 18:13:21 +08:00
Rename NetchLib to SearchComboBox
This commit is contained in:
72
Netch.sln
72
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
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NetchLib\NetchLib.csproj" />
|
||||
<ProjectReference Include="..\SearchComboBox\SearchComboBox.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
3
NetchLib/.gitignore
vendored
3
NetchLib/.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
/bin
|
||||
/obj
|
||||
/NetchLib.csproj.user
|
||||
3
SearchComboBox/.gitignore
vendored
Normal file
3
SearchComboBox/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/bin
|
||||
/obj
|
||||
/SearchComboBox.csproj.user
|
||||
@@ -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")]
|
||||
@@ -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<object>().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<object>().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<object>().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<object>().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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<Platforms>x64</Platforms>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
Reference in New Issue
Block a user