增加首页搜索框,支持快速搜索目录和控件
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.menu = new AntdUI.Menu();
|
||||||
this.panel_content = new AntdUI.StackPanel();
|
this.panel_content = new AntdUI.StackPanel();
|
||||||
this.label1 = new AntdUI.Label();
|
this.label1 = new AntdUI.Label();
|
||||||
|
this.input_search = new AntdUI.Input();
|
||||||
this.titlebar.SuspendLayout();
|
this.titlebar.SuspendLayout();
|
||||||
this.panel_content.SuspendLayout();
|
this.panel_content.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// titlebar
|
// titlebar
|
||||||
//
|
//
|
||||||
|
this.titlebar.Controls.Add(this.input_search);
|
||||||
this.titlebar.Controls.Add(this.button_color);
|
this.titlebar.Controls.Add(this.button_color);
|
||||||
this.titlebar.Controls.Add(this.buttonSZ);
|
this.titlebar.Controls.Add(this.buttonSZ);
|
||||||
this.titlebar.Dock = System.Windows.Forms.DockStyle.Top;
|
this.titlebar.Dock = System.Windows.Forms.DockStyle.Top;
|
||||||
@ -121,6 +123,17 @@
|
|||||||
this.label1.Text = "欢迎使用 AntdUI Demo";
|
this.label1.Text = "欢迎使用 AntdUI Demo";
|
||||||
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
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
|
// MainWindow
|
||||||
//
|
//
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||||
@ -132,6 +145,7 @@
|
|||||||
this.Controls.Add(this.titlebar);
|
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.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.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||||
|
this.Mode = AntdUI.TAMode.Auto;
|
||||||
this.Name = "MainWindow";
|
this.Name = "MainWindow";
|
||||||
this.Opacity = 0.99D;
|
this.Opacity = 0.99D;
|
||||||
this.Padding = new System.Windows.Forms.Padding(6, 0, 0, 6);
|
this.Padding = new System.Windows.Forms.Padding(6, 0, 0, 6);
|
||||||
@ -153,5 +167,6 @@
|
|||||||
private AntdUI.Button buttonSZ;
|
private AntdUI.Button buttonSZ;
|
||||||
private AntdUI.Button button_color;
|
private AntdUI.Button button_color;
|
||||||
private AntdUI.Label label1;
|
private AntdUI.Label label1;
|
||||||
|
private AntdUI.Input input_search;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,12 +31,20 @@ namespace AntdUIDemo
|
|||||||
{
|
{
|
||||||
buttonSZ.Click += ButtonSZ_Click;
|
buttonSZ.Click += ButtonSZ_Click;
|
||||||
button_color.Click += Button_color_Click;
|
button_color.Click += Button_color_Click;
|
||||||
|
input_search.TextChanged += Input_search_textchanged;
|
||||||
menu.SelectChanged += Menu_SelectChanged;
|
menu.SelectChanged += Menu_SelectChanged;
|
||||||
//监听系统深浅色变化
|
//监听系统深浅色变化
|
||||||
SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
|
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)
|
private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Category == UserPreferenceCategory.General)
|
if (e.Category == UserPreferenceCategory.General)
|
||||||
@ -113,25 +121,59 @@ 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();
|
menu.Items.Clear();
|
||||||
|
|
||||||
foreach (var rootItem in DataUtil.MenuItems)
|
foreach (var rootItem in DataUtil.MenuItems)
|
||||||
{
|
{
|
||||||
|
var rootKey = rootItem.Key.ToLower();
|
||||||
var rootMenu = new AntdUI.MenuItem { Text = rootItem.Key };
|
var rootMenu = new AntdUI.MenuItem { Text = rootItem.Key };
|
||||||
|
bool rootVisible = false; // 用于标记是否显示根节点
|
||||||
|
|
||||||
foreach (var item in rootItem.Value)
|
foreach (var item in rootItem.Value)
|
||||||
{
|
{
|
||||||
var menuItem = new AntdUI.MenuItem
|
var childText = item.Text.ToLower();
|
||||||
{
|
|
||||||
Text = item.Text,
|
|
||||||
IconSvg = item.IconSvg,
|
|
||||||
Tag = item.Tag,
|
|
||||||
};
|
|
||||||
rootMenu.Sub.Add(menuItem);
|
|
||||||
}
|
|
||||||
menu.Items.Add(rootMenu);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 如果子节点包含搜索文本
|
||||||
|
if (childText.Contains(filter))
|
||||||
|
{
|
||||||
|
var menuItem = new AntdUI.MenuItem
|
||||||
|
{
|
||||||
|
Text = item.Text,
|
||||||
|
IconSvg = item.IconSvg,
|
||||||
|
Tag = item.Tag,
|
||||||
|
};
|
||||||
|
rootMenu.Sub.Add(menuItem);
|
||||||
|
rootVisible = true; // 如果有子节点包含,则显示根节点
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果根节点包含搜索文本,或有可见的子节点,则显示根节点
|
||||||
|
if (rootKey.Contains(filter) || rootVisible)
|
||||||
|
{
|
||||||
|
menu.Items.Add(rootMenu);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Menu_SelectChanged(object sender, MenuSelectEventArgs e)
|
private void Menu_SelectChanged(object sender, MenuSelectEventArgs e)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user