System::Void ENTER_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) { Point location = this->Location; this->Text = location.ToString(); int static k = 0; if (e->KeyCode == Keys::Enter) { if (k == 0) { this->Location = System::Drawing::Point(0, 0); k=1; } else { this->Location = System::Drawing::Point(location); k=0; } } } 

enter image description here Variable value at the first click on Enter

enter image description here At the second

  • What should this code do and what is wrong? - default locale
  • The component should move to zero coordinates, and then return to the original place, when you press Enter - Kirby

1 answer 1

Now the code at even steps gets the current Location and sets it back without changing anything:

 Point location = this->Location; //... this->Location = System::Drawing::Point(location); 

To return to the previous position, you need to save it.

It might look like this:

 //инициализация static Point previousLocation = Point(0,0); //сохраняем положение Point location = this->Location; //... //установливаем на предыдущее место this->Location = previousLocation; //запоминаем для следующего раза previousLocation = location;