keydown event, not working.
I'm trying to move this button in the x axis.. I used the following code.
Code:
private: System::Void Form1_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
if( e->KeyCode==Keys::Up)
{
++x;
label1->Text="up ";
button1->Location = Point(x, y);
}
But nothing happens... But when i try the same thing after putting a textbox, it works. Heres the code.
Code:
private: System::Void textBox1_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
if( e->KeyCode==Keys::Up)
{
++x;
label1->Text="up ";
button1->Location = Point(x, y);
}
Any ideas?
Re: keydown event, not working.
Looks like the focused control (the button, most probably) consumes the keystrokes before the form gets notice of them. Try setting the form's KeyPreview property to true.
Re: keydown event, not working.
Thanks . will check it out. :)