WindowsForm加入WebBrowser控件后为什么Keydown事件无法触发?
其中KeyPreview属性已经设置为了true,还是无法出发KeyDown事件,代码如下:WebBrowserbrowser=newWebBrowser();publi...
其中KeyPreview属性已经设置为了true,还是无法出发KeyDown事件,代码如下:
WebBrowser browser = new WebBrowser();
public Form1()
{
InitializeComponent();
browser.IsWebBrowserContextMenuEnabled = false;//设置不允许鼠标右键点击
browser.Dock = DockStyle.Fill;
browser.Capture = false;
browser.Navigate("www.baidu.com");
Controls.Add(browser);
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
//MessageBox.Show(e.KeyValue.ToString());
if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D1)
{
if (WindowState == FormWindowState.Maximized)
{
WindowState = FormWindowState.Normal;
}
else
{
WindowState = FormWindowState.Maximized;
}
}
} 展开
WebBrowser browser = new WebBrowser();
public Form1()
{
InitializeComponent();
browser.IsWebBrowserContextMenuEnabled = false;//设置不允许鼠标右键点击
browser.Dock = DockStyle.Fill;
browser.Capture = false;
browser.Navigate("www.baidu.com");
Controls.Add(browser);
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
//MessageBox.Show(e.KeyValue.ToString());
if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D1)
{
if (WindowState == FormWindowState.Maximized)
{
WindowState = FormWindowState.Normal;
}
else
{
WindowState = FormWindowState.Maximized;
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询