0
Hello, I’m starting now to program in c++ and I’m developing a college project, it’s a periodic table. We thought of using a button for each element (118 in total). My goal is to animate the button so that when the mouse passes over it doubles in size, for this I used a Timer
:
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
int x = 70;
if(x <= 140){
button1->Size = System::Drawing::Size(x, x);
x += 5;
}else{ timer1-> Enabled = false;}
}
private: System::Void button1_MouseHover(System::Object^ sender, System::EventArgs^ e) {
timer1 -> Enabled = true;
}
I tried several things, but so far I could not automate this process, I wanted to create some function that linked the event timer with the button I want to animate, for example:
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e, System::Windows::Forms::Button^ bt) {
int x = 70;
if(x <= 140){
bt->Size = System::Drawing::Size(x, x);
x += 5;
}else{ timer1-> Enabled = false;}
}
or something like:
scaleUp(System::Windows::Forms::Button^ bt);
private: System::Void button1_MouseHover(System::Object^ sender, System::EventArgs^ e) {
scaleUp(button1);
}
How to create a solution to the problem without creating 118 timers?
the tag is wrong, that’s not C++, it’s that Microsoft dialect called "C++/CX" or something...
– zentrunix
Probably the simplest solution would be to link the same Mousehover event on all buttons and within the code programmed for the event to cast the System::Object parameter for System::Windows:Forms::Button using dynamic_cast. Done this you can call scaleUp by passing as parameter the pointer of type Button.
– Bruno Bermann
I’ll try that, thank you very much.
– Alécio Gomes