Question:
In Visual C++, how do I pass a variable from an event to another event?
WickeTD
2011-02-24 14:52:29 UTC
private: System::Void checkBox1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
int col;
if (this->checkBox1->Checked == true) {
col = 1;
}
}


private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e)
{
UNREFERENCED_PARAMETER(sender);
UNREFERENCED_PARAMETER(e);
OpenGL->Render(HERE,0.0);
OpenGL->SwapOpenGLBuffers();
}


I am fairly new to C++ and this is an urgent problem because I must have fixed this problem within one/two hours.
It is also late at night so I'm having big problems getting to understand what to use to solve this.
How do I pass variable col from the first event to the HERE in the second one?
Thanks in advance.
Three answers:
?
2011-02-24 14:59:05 UTC
Isn't this->checkBox1 available in timer1_Tick()? There's no way for an un-called event handler to hand anything to another event handler, and then only if it calls the second handler.



Hope that helps.
husoski
2011-02-24 23:05:58 UTC
If both methods belong to the same object, you could create a private member variable to hold the information. Otherwise, the checkBox1_CheckedChanged() method will have to call a method of whatever the object timer1_Tick() belongs to, informing that object where to render itself on the next timer tick.
Zero
2011-02-24 23:03:26 UTC
if i understand this correctly you can use a global Variable

for the col

and then use it for the timer event


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...