using System; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using GrasscutterTools.Properties; namespace GrasscutterTools.Utils { public static class UIUtil { /// /// 播放按钮完成动画 /// /// /// public static async Task ButtonComplete(Button btn) { var t = btn.Text; btn.Text = "√"; btn.Enabled = false; await Task.Delay(300); btn.Text = t; btn.Enabled = true; } /// /// 列表过滤 /// /// 列表控件 /// 数据源 /// 过滤内容 public static void ListBoxFilter(ListBox listBox, string[] source, string filter) { filter = filter.Trim(); listBox.BeginUpdate(); listBox.Items.Clear(); if (source != null && source.Length > 0) { if (string.IsNullOrEmpty(filter)) listBox.Items.AddRange(source); else listBox.Items.AddRange(source.Where(n => n.Contains(filter)).ToArray()); } listBox.EndUpdate(); } /// /// 使用浏览器打开网址 /// /// 网址 public static void OpenURL(string url) { try { System.Diagnostics.Process.Start(url); } catch (Exception) { MessageBox.Show(Resources.BrowserOpenFailedTip + "\n " + url, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } /// /// 提示气泡对象 /// private static readonly ToolTip TTip = new ToolTip(); /// /// 在指定控件上显示提示气泡 /// /// 消息 /// 控件 public static void ShowTip(string message, Control control) { TTip.Show(message, control, 0, control.Size.Height, 3000); } } }