C# winform 无API函数实现系统快捷键
protected void ErgodicChildrenControls(Control parent, KeyEventArgs e)
{
DataTable dt=new DataTable();
//dt= bga.GetTable("select * from d_short_keys where login_code='" + bga.LoginID + "'");
dt = bga.GetTable("select * from d_code_list where mark=upper('short_key')");
if (dt == null || dt.Rows.Count == 0) return;//没有设置快捷键,返回。
foreach (Control c in parent.Controls)
{
if (c is DevExpress.XtraEditors.SimpleButton)
{
DevExpress.XtraEditors.SimpleButton btn = (DevExpress.XtraEditors.SimpleButton)c;
for (int i = 0; i < dt.Rows.Count; i++)
{
if (e.Alt && e.KeyCode.ToString() == dt.Rows[i]["B_CODE"].ToString() && btn.Text.Trim()==dt.Rows[i]["CODE_NAME"].ToString() && btn.Parent.GetType().ToString() == "DevExpress.XtraBars.Docking.ControlContainer")
{
btn.PerformClick();
return;
}
}
}
if (c.Controls.Count > 0) // 判断该控件是否有下属控件。
{
ErgodicChildrenControls(c, e); //递归,访问该控件的下属控件集。
}
}
}