Remove SearchComboBox

This commit is contained in:
ChsBuffer
2021-03-27 17:56:34 +08:00
parent b215b2caa8
commit 8254482799
7 changed files with 3 additions and 262 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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<Server>().FirstOrDefault(s => s.Remark.Equals(profile.ServerRemark));
var mode = ModeComboBox.Items.Cast<Models.Mode>().FirstOrDefault(m => m.Remark.Equals(profile.ModeRemark));

View File

@@ -77,7 +77,6 @@
<ItemGroup>
<ProjectReference Include="..\Interop.nfapinet\Interop.nfapinet.csproj" />
<ProjectReference Include="..\SearchComboBox\SearchComboBox.csproj" />
</ItemGroup>
<ItemGroup>

View File

@@ -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")]

View File

@@ -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<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);
}
}
}
}

View File

@@ -1,21 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows7</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Platforms>AnyCPU</Platforms>
<UseWindowsForms>true</UseWindowsForms>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
<!-- NET Framework -->
<Reference Include="System.Windows.Forms" />
</ItemGroup>
</Project>