diff --git a/AppSearch.cs b/AppSearch.cs new file mode 100644 index 0000000..ac88f75 --- /dev/null +++ b/AppSearch.cs @@ -0,0 +1,57 @@ +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); + } + } +} diff --git a/AppStore.csproj b/AppStore.csproj index aa4d5db..fae7734 100644 --- a/AppStore.csproj +++ b/AppStore.csproj @@ -33,4 +33,8 @@ + + + + diff --git a/renexe.bat b/renexe.bat index 2201459..86e2431 100644 --- a/renexe.bat +++ b/renexe.bat @@ -1,2 +1,2 @@ -ren bin\Release\net8.0-windows\win-x86\publish\AppStore.exe kortapp.exe -ren bin\Release\net8.0-windows\win-x64\publish\AppStore.exe kortapp.exe \ No newline at end of file +ren bin\Release\net8.0-windows\win-x86\publish\AppStore.exe kortapp-z.exe +ren bin\Release\net8.0-windows\win-x64\publish\AppStore.exe kortapp-z.exe \ No newline at end of file