При нажатии на кнопку она постепенно увеличивается на всё окно
Почти дословная цитата... Создан пустой проект Windows Forms с одной формой, вот весь добавленный код (кстати, Studio 2019 уже не ругается на эти проекты как на "устаревшие", а в 2013-м они было "устарели")
Как для любой анимации, нужен таймер и всё.
//... #pragma endregion private: bool started; int dx, dy, startWidth, startHeight; Button ^b; Timer ^t; private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) { b = gcnew Button(); b->Text = "Click me!"; b->Left = (this->ClientSize.Width - b->Width) / 2; b->Top = (this->ClientSize.Height - b->Height) / 2; b->Click += gcnew System::EventHandler (this, &MyForm::b_Click); b->Parent = this; t = gcnew Timer(); t->Enabled = true; t->Interval = 50; t->Tick += gcnew System::EventHandler (this, &MyForm::t_Tick); startWidth = b->Width; startHeight = b->Height; dx = dy = 2; started = false; } private: System::Void b_Click(System::Object^ sender, System::EventArgs^ e) { started = !started; } private: System::Void t_Tick(System::Object^ sender, System::EventArgs^ e) { if (started) { b->Width += dx; if (b->Width < startWidth || b->Width > this->ClientSize.Width - 2) dx = -dx; b->Height += dy; if (b->Height < startHeight || b->Height > this->ClientSize.Height - 2) dy = -dy; b->Left = (this->ClientSize.Width - b->Width) / 2; b->Top = (this->ClientSize.Height - b->Height) / 2; } } //...
Можно не создавать отдельное свойство started
, а переключать состояние таймера
private: System::Void b_Click(System::Object^ sender, System::EventArgs^ e) { t->Enabled = !t->Enabled; }
23.11.2019, 15:15 [1510 просмотров]