using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace AppStore { public static class AppSearch { /// /// 搜索应用卡片 /// /// 包含应用卡片的FlowLayoutPanel /// 搜索文本 public static void SearchApps(FlowLayoutPanel flowPanel, string searchText) { if (flowPanel == null || string.IsNullOrWhiteSpace(searchText)) { ShowAllApps(flowPanel); return; } foreach (Control control in flowPanel.Controls) { if (control is AppCard appCard) { bool isMatch = IsMatchSearch(appCard.AppName, searchText); control.Visible = isMatch; } } } /// /// 显示所有应用卡片 /// public static void ShowAllApps(FlowLayoutPanel? flowPanel) { if (flowPanel == null) return; foreach (Control control in flowPanel.Controls) { control.Visible = true; } } /// /// 检查应用名称是否匹配搜索文本 /// private static bool IsMatchSearch(string appName, string searchText) { if (string.IsNullOrEmpty(appName)) return false; // 不区分大小写比较 return appName.Contains(searchText, StringComparison.OrdinalIgnoreCase); } } }