键盘快捷键不能正常打开表格3

本文关键字:表格 常打开 快捷键 不能 键盘 | 更新日期: 2023-09-27 18:18:57

我需要表单添加alt+1键来打开表单3,但由于某种原因,当我调试并按下快捷键时,它没有打开快捷键

下面是表单2

中的代码段
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Alt && e.KeyCode == Keys.A)
    {
        Form3 f3 = new Form3();
        f3.ShowDialog();
    }
}

正如我所说,如果它有帮助,它不会像预期的那样打开形式3,这里是我在形式2中使用的整个代码:(更新)(解决)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            this.KeyPreview = true;
            this.KeyDown += new KeyEventHandler(Form1_KeyDown);
        }
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            var myForm = new Form2();
            myForm.Show();
        }
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Alt && e.KeyCode == Keys.A)
            {
                Form3 f3 = new Form3();
                f3.ShowDialog();
            }
        }
        private void Form2_Load(object sender, EventArgs e)
        {
        }
    }
}

键盘快捷键不能正常打开表格3

您需要将表单的KeyPreview属性设置为True