我在一个群组盒子里有两个无线电按钮。还有一个图片盒,我想用箭头键四处移动。没有无线电按钮,一切都很好。但是当添加无线电按钮时,就像选择了无线电台,而所有的箭头键都是在不同的无线电台之间交替的。
基本上:如何让箭头与Form1对话,而不是使用无线电按钮?
发布于 2022-03-17 20:31:39
您可以这样重写ProcessCmdKey()
:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
switch (keyData)
{
case Keys.Left:
pictureBox1.Location = new Point(pictureBox1.Location.X - 1, pictureBox1.Location.Y);
return true;
case Keys.Right:
pictureBox1.Location = new Point(pictureBox1.Location.X + 1, pictureBox1.Location.Y);
return true;
case Keys.Up:
pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y - 1);
return true;
case Keys.Down:
pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y + 1);
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
https://stackoverflow.com/questions/71518180
复制相似问题