增加首页搜索框,支持快速搜索目录和控件
This commit is contained in:
parent
e3cdd6ec40
commit
1d69359052
15
MainWindow.Designer.cs
generated
15
MainWindow.Designer.cs
generated
@ -36,12 +36,14 @@
|
||||
this.menu = new AntdUI.Menu();
|
||||
this.panel_content = new AntdUI.StackPanel();
|
||||
this.label1 = new AntdUI.Label();
|
||||
this.input_search = new AntdUI.Input();
|
||||
this.titlebar.SuspendLayout();
|
||||
this.panel_content.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// titlebar
|
||||
//
|
||||
this.titlebar.Controls.Add(this.input_search);
|
||||
this.titlebar.Controls.Add(this.button_color);
|
||||
this.titlebar.Controls.Add(this.buttonSZ);
|
||||
this.titlebar.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
@ -121,6 +123,17 @@
|
||||
this.label1.Text = "欢迎使用 AntdUI Demo";
|
||||
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// input_search
|
||||
//
|
||||
this.input_search.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.input_search.Font = new System.Drawing.Font("Microsoft YaHei UI", 10F);
|
||||
this.input_search.Location = new System.Drawing.Point(596, 0);
|
||||
this.input_search.Name = "input_search";
|
||||
this.input_search.PlaceholderText = "输入关键字搜索...";
|
||||
this.input_search.PrefixSvg = "SearchOutlined";
|
||||
this.input_search.Size = new System.Drawing.Size(200, 40);
|
||||
this.input_search.TabIndex = 2;
|
||||
//
|
||||
// MainWindow
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
@ -132,6 +145,7 @@
|
||||
this.Controls.Add(this.titlebar);
|
||||
this.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.Mode = AntdUI.TAMode.Auto;
|
||||
this.Name = "MainWindow";
|
||||
this.Opacity = 0.99D;
|
||||
this.Padding = new System.Windows.Forms.Padding(6, 0, 0, 6);
|
||||
@ -153,5 +167,6 @@
|
||||
private AntdUI.Button buttonSZ;
|
||||
private AntdUI.Button button_color;
|
||||
private AntdUI.Label label1;
|
||||
private AntdUI.Input input_search;
|
||||
}
|
||||
}
|
||||
@ -31,12 +31,20 @@ namespace AntdUIDemo
|
||||
{
|
||||
buttonSZ.Click += ButtonSZ_Click;
|
||||
button_color.Click += Button_color_Click;
|
||||
|
||||
input_search.TextChanged += Input_search_textchanged;
|
||||
menu.SelectChanged += Menu_SelectChanged;
|
||||
//监听系统深浅色变化
|
||||
SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
|
||||
}
|
||||
|
||||
private void Input_search_textchanged(object sender, EventArgs e)
|
||||
{
|
||||
titlebar.Loading = true;
|
||||
var text = input_search.Text.ToLower(); // 将输入文本转换为小写,确保搜索不区分大小写
|
||||
LoadMenu(text); // 传递搜索文本
|
||||
titlebar.Loading = false;
|
||||
}
|
||||
|
||||
private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
|
||||
{
|
||||
if (e.Category == UserPreferenceCategory.General)
|
||||
@ -113,13 +121,41 @@ namespace AntdUIDemo
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadMenu()
|
||||
//private void LoadMenu()
|
||||
//{
|
||||
// menu.Items.Clear();
|
||||
// foreach (var rootItem in DataUtil.MenuItems)
|
||||
// {
|
||||
// var rootMenu = new AntdUI.MenuItem { Text = rootItem.Key };
|
||||
// foreach (var item in rootItem.Value)
|
||||
// {
|
||||
// var menuItem = new AntdUI.MenuItem
|
||||
// {
|
||||
// Text = item.Text,
|
||||
// IconSvg = item.IconSvg,
|
||||
// Tag = item.Tag,
|
||||
// };
|
||||
// rootMenu.Sub.Add(menuItem);
|
||||
// }
|
||||
// menu.Items.Add(rootMenu);
|
||||
// }
|
||||
//}
|
||||
private void LoadMenu(string filter = "")
|
||||
{
|
||||
menu.Items.Clear();
|
||||
|
||||
foreach (var rootItem in DataUtil.MenuItems)
|
||||
{
|
||||
var rootKey = rootItem.Key.ToLower();
|
||||
var rootMenu = new AntdUI.MenuItem { Text = rootItem.Key };
|
||||
bool rootVisible = false; // 用于标记是否显示根节点
|
||||
|
||||
foreach (var item in rootItem.Value)
|
||||
{
|
||||
var childText = item.Text.ToLower();
|
||||
|
||||
// 如果子节点包含搜索文本
|
||||
if (childText.Contains(filter))
|
||||
{
|
||||
var menuItem = new AntdUI.MenuItem
|
||||
{
|
||||
@ -128,10 +164,16 @@ namespace AntdUIDemo
|
||||
Tag = item.Tag,
|
||||
};
|
||||
rootMenu.Sub.Add(menuItem);
|
||||
rootVisible = true; // 如果有子节点包含,则显示根节点
|
||||
}
|
||||
menu.Items.Add(rootMenu);
|
||||
}
|
||||
|
||||
// 如果根节点包含搜索文本,或有可见的子节点,则显示根节点
|
||||
if (rootKey.Contains(filter) || rootVisible)
|
||||
{
|
||||
menu.Items.Add(rootMenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Menu_SelectChanged(object sender, MenuSelectEventArgs e)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user