Как считать значение клавиш C++/CLI Windows Forms
подскажите пожалуйста, необходимо при нажатии пользователем клавиши перемещать доску в игре Ping-Pong,для кого элемента формы необходимо описать действие? Картинка рисуется на PictureBox #pragma once
#include "Header.h"
namespace ooplab4test {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Drawing::Drawing2D;
/// <summary>
/// Сводка для MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
myTable = gcnew PongTable(pictureBox1);
myTable->Add(gcnew Player(480, 220, 60, 20, Brushes::Black, 0));
myTable->Add(gcnew Player(480, 220, 60, 20, Brushes::Black, 1));
}
protected:
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
private: System::Windows::Forms::Timer^ timer1;
private: bool movingw;
private: bool movings;
private: System::ComponentModel::IContainer^ components;
private: System::Windows::Forms::Button^ button1;
private:
PongTable^ myTable;
#pragma region Windows Form Designer generated code
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
this->button1 = (gcnew System::Windows::Forms::Button());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->Location = System::Drawing::Point(35, 12);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(500, 500);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
//
// timer1
//
this->timer1->Tick += gcnew System::EventHandler(this, &MyForm::timer1_Tick);
//
// button1
//
this->button1->Location = System::Drawing::Point(259, 219);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 1;
this->button1->Text = L"Старт!";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(622, 603);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->Name = L"MyForm";
this->Text = L"MyForm";
this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &MyForm::MyForm_KeyDown);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
myTable->Draw();
if (movingw) {
myTable->MoveUp();
}
if (movings) {
myTable->MoveDown();
}
movingw = false;
movings = false;
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
button1->Visible = false;
timer1->Start();
}
private: System::Void MyForm_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
if (e->KeyCode == Keys::W)
movingw = true;
else if (e->KeyCode == Keys::S)
movings = true;
}
В последней функции, я предполагала, будут обрабатываться эти клавиши, помогите пожалуйста.