mirror of
https://github.com/zs-yg/kortapp-z.git
synced 2025-12-06 08:00:44 +08:00
58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
|
|
namespace AppStore
|
|
{
|
|
public static class AppSearch
|
|
{
|
|
/// <summary>
|
|
/// 搜索应用卡片
|
|
/// </summary>
|
|
/// <param name="flowPanel">包含应用卡片的FlowLayoutPanel</param>
|
|
/// <param name="searchText">搜索文本</param>
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示所有应用卡片
|
|
/// </summary>
|
|
public static void ShowAllApps(FlowLayoutPanel? flowPanel)
|
|
{
|
|
if (flowPanel == null) return;
|
|
|
|
foreach (Control control in flowPanel.Controls)
|
|
{
|
|
control.Visible = true;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查应用名称是否匹配搜索文本
|
|
/// </summary>
|
|
private static bool IsMatchSearch(string appName, string searchText)
|
|
{
|
|
if (string.IsNullOrEmpty(appName)) return false;
|
|
|
|
// 不区分大小写比较
|
|
return appName.Contains(searchText, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
}
|
|
}
|