我正在寻找一种在C#中的Windows窗体应用程序中实现常用Windows键盘快捷键(例如Ctrl+ F,Ctrl+ N)的最佳方法.
该应用程序有一个主窗体,可以容纳许多子窗体(一次一个).当用户点击Ctrl+时F,我想显示自定义搜索表单.搜索表单取决于应用程序中当前打开的子表单.
我想在ChildForm_KeyDown事件中使用这样的东西:
if (e.KeyCode == Keys.F && Control.ModifierKeys == Keys.Control)
// Show search form
Run Code Online (Sandbox Code Playgroud)
但这不起作用.按键时,事件甚至不会触发.解决办法是什么?
我有一个列表框,我可以用一个按钮删除项目但我想也能用我的键盘上的删除键删除,我找不到谷歌的方式所以有人可以请帮助我
编辑 它的winform应用程序
这是删除按钮的代码:
private void Button3Click(object sender, EventArgs e)
{
var application = this.GetCurrentApplication();
if (application == null)
{
MessageBox.Show("No Application selected");
return;
}
if (MessageBox.Show("You are about to delete application: " + Environment.NewLine + _applicationListBox.SelectedItem + Environment.NewLine + "Are you sure you want to delete the application?", "", MessageBoxButtons.YesNo) == DialogResult.No)
{
MessageBox.Show("The application will not be deleted.", "", MessageBoxButtons.OK);
}
else if (this._applicationListBox.SelectedIndex >= 0)
{
int index = _applicationListBox.SelectedIndex;
_toepassingIniFile.ToePassingen.Remove(application);
if (index == _toepassingIniFile.ToePassingen.Count)
--index;
application …Run Code Online (Sandbox Code Playgroud)