'How do I make the arrowkeys talk to Form1 instead of the radiobuttons?
I have two radiobuttons inside a groupbox. And a picturebox I want to move around with arrow keys. Without the radiobuttons, everything works completely fine. But when the radiobuttons are added, it's like the radioboxes are selected, and all the arrow-keys do, is just alternating between different radioboxes.
Basically: How do I make the arrowkeys talk to Form1 instead of the radiobuttons?
Solution 1:[1]
You can override ProcessCmdKey() like this:
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);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Idle_Mind |
