:bug:修复模式选择下拉框的崩溃bug

This commit is contained in:
Amazing_DM
2020-05-15 20:02:15 +08:00
parent f71b319741
commit debfa76ea2
3 changed files with 61 additions and 52 deletions

View File

@@ -255,7 +255,7 @@ namespace Netch.Forms
private void SaveConfigs()
{
Global.Settings.ServerComboBoxSelectedIndex = ServerComboBox.SelectedIndex;
if (ModeComboBox.SelectedItem != null)
if (ModeComboBox.Items.Count!=0 && ModeComboBox.SelectedItem != null)
{
if (ModeComboBox.Tag is object[] list)

View File

@@ -1,5 +1,4 @@
using Microsoft.Win32;
using System;
using System;
using System.Globalization;
using System.IO;
using System.Text;
@@ -122,8 +121,11 @@ namespace Netch
public static void Application_OnException(object sender, ThreadExceptionEventArgs e)
{
MessageBox.Show(e.Exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
if (!e.Exception.ToString().Contains("ComboBox"))
{
MessageBox.Show(e.Exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//Application.Exit();
}
}
}

View File

@@ -82,69 +82,76 @@ namespace System.Windows.Forms
private object[] newList;
private void ReevaluateCompletionList()
{
var currentSearchTerm = Text.ToLowerInvariant();
if (currentSearchTerm == _previousSearchTerm) return;
_previousSearchTerm = currentSearchTerm;
try
{
SuspendLayout();
var originalList = (object[])Tag;
if (originalList == null)
{
Tag = originalList = Items.Cast<object>().ToArray();
}
if (string.IsNullOrEmpty(currentSearchTerm))
{
if (Items.Count == originalList.Length) return;
newList = originalList;
}
else
{
newList = originalList.Where(x => x.ToString().ToLowerInvariant().Contains(currentSearchTerm)).ToArray();
}
var currentSearchTerm = Text.ToLowerInvariant();
if (currentSearchTerm == _previousSearchTerm) return;
_previousSearchTerm = currentSearchTerm;
try
{
while (Items.Count > 0)
SuspendLayout();
var originalList = (object[])Tag;
if (originalList == null)
{
Items.RemoveAt(0);
Tag = originalList = Items.Cast<object>().ToArray();
}
}
catch
{
if (string.IsNullOrEmpty(currentSearchTerm))
{
if (Items.Count == originalList.Length) return;
newList = originalList;
}
else
{
newList = originalList.Where(x => x.ToString().ToLowerInvariant().Contains(currentSearchTerm)).ToArray();
}
try
{
Items.Clear();
while (Items.Count > 0)
{
Items.RemoveAt(0);
}
}
catch
{
// ignored
try
{
Items.Clear();
}
catch
{
// ignored
}
}
}
Items.AddRange(newList.ToArray());
Items.AddRange(newList.ToArray());
}
finally
{
if (currentSearchTerm.Length >= 2 && !DroppedDown)
{
DroppedDown = true;
Cursor.Current = Cursors.Default;
Text = currentSearchTerm;
Select(currentSearchTerm.Length, 0);
}
if (Items.Count > 0)
{
DroppedDown = false;
DroppedDown = true;
}
ResumeLayout(true);
}
}
finally
catch
{
if (currentSearchTerm.Length >= 2 && !DroppedDown)
{
DroppedDown = true;
Cursor.Current = Cursors.Default;
Text = currentSearchTerm;
Select(currentSearchTerm.Length, 0);
}
if (Items.Count > 0)
{
DroppedDown = false;
DroppedDown = true;
}
ResumeLayout(true);
// ignored
}
}
}