箭頭鍵應該只滾動圖片框(放置在面板中)。它作業正常。但它也會滾動瀏覽組合框專案,盡管它是關閉的(droppedUp)。如何禁用它?
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.DropDownStyle = ComboBoxStyle.DropDown;
comboBox1.DroppedDown = false;
comboBox1.Items.Add("111");
comboBox1.Items.Add("222");
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Down)
{
Point current = panel1.AutoScrollPosition;
Point scrolled = new Point(current.X, -current.Y 50);
panel1.AutoScrollPosition = scrolled;
}
return base.ProcessCmdKey(ref msg, keyData);
}
我已經閱讀了 Control.PreviewKeyDown 事件: 預覽鍵事件 ,還找到了另一個示例: 預覽鍵事件 ,但我無法理解它在我的案例中是如何使用的。
uj5u.com熱心網友回復:
正如 Hans Passant 評論的那樣,您必須回傳 true。此外,添加一些其他可能會更改組合框中所選專案的鍵:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Down ||
keyData == Keys.Up ||
keyData == Keys.PageDown ||
keyData == Keys.PageUp)
{
Point current = panel1.AutoScrollPosition;
Point scrolled = new Point(current.X, -current.Y 50);
panel1.AutoScrollPosition = scrolled;
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/475050.html
