Commit 27316c1c authored by 段廷瑞's avatar 段廷瑞

pref: 回车触发搜索如果没有结果,则给出提示

parent ed4a45df
......@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
......@@ -460,6 +461,39 @@ namespace Tools.MyUtils
new wMsgBox().Show(msg, width, height);
}
/// <summary>
/// Toast提示(自动关闭)
/// </summary>
/// <param name="msg">消息</param>
/// <param name="durationMs">显示时长(毫秒),默认2秒</param>
public static void Toast(string msg, int durationMs = 2000)
{
var timer = new System.Windows.Forms.Timer { Interval = durationMs };
var form = new Form
{
FormBorderStyle = FormBorderStyle.None,
StartPosition = FormStartPosition.CenterScreen,
BackColor = Color.FromArgb(255, 255, 225),
Size = new Size(250, 50),
TopMost = true,
ShowInTaskbar = false,
};
form.Controls.Add(new Label
{
Text = msg,
Dock = DockStyle.Fill,
TextAlign = ContentAlignment.MiddleCenter,
Font = new Font("微软雅黑", 9F),
});
timer.Tick += (s, e) =>
{
timer.Stop();
form.Close();
timer.Dispose();
};
timer.Start();
form.Show();
}
/// <summary>
/// 是否提示
/// </summary>
/// <param name="msg"></param>
......
......@@ -69,6 +69,9 @@ namespace Tools.UI
return;
this.RefrashData(false);
if (lsbTableInfo.Items.Count == 0)
Utils.Toast("未找到匹配结果");
}
}
......
......@@ -1208,7 +1208,7 @@ namespace Tools.UI
}
else
{
Utils.Tip(notFoundMessage);
Utils.Toast(notFoundMessage);
}
}
#endregion
......
......@@ -213,7 +213,8 @@ namespace Tools.UI
{
if (e.KeyCode == Keys.Enter)
{
this.SetTreeNodeBackColor(this.myTreeView1.Nodes, this.tbSearch.Text.Trim());
if (!this.SetTreeNodeBackColor(this.myTreeView1.Nodes, this.tbSearch.Text.Trim()))
Utils.Toast("未找到匹配结果");
}
}
/// <summary>
......@@ -221,13 +222,17 @@ namespace Tools.UI
/// </summary>
/// <param name="nodes">树节点</param>
/// <param name="SearchText">查询字串</param>
private void SetTreeNodeBackColor(TreeNodeCollection nodes, string SearchText)
/// <returns>是否找到匹配项</returns>
private bool SetTreeNodeBackColor(TreeNodeCollection nodes, string SearchText)
{
bool found = false;
foreach (TreeNode n in nodes)
{
//查询条件不为空并且包含查询字符,则设置背景色
bool IsSearched = !string.IsNullOrEmpty(SearchText) && n.Text.Contains(SearchText);
n.BackColor = IsSearched ? Color.LightBlue : Color.White;
if (IsSearched)
found = true;
#region 节点展开与折叠
if (IsSearched)
......@@ -245,8 +250,10 @@ namespace Tools.UI
#endregion
//递归子节点
this.SetTreeNodeBackColor(n.Nodes, SearchText);
if (this.SetTreeNodeBackColor(n.Nodes, SearchText))
found = true;
}
return found;
}
/// <summary>
/// 展开查询节点的父节点
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment