-
August 18th, 2012, 10:27 AM
#1
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?
-
August 18th, 2012, 08:45 PM
#2
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.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
August 19th, 2012, 06:00 AM
#3
Re: keydown event, not working.
Thanks . will check it out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|