So I have been playing around with windows forms for a little while now. But I have ran into something rather strange.
When I try to print the i value to the text box it does not seem to update. I am a little bit dumb struck as to why this is. I must ask is there anyway to fix this and why is this happening.
1 2 3 4 5 6 7 8 9 10 11
// Full code if you need it http://pastebin.com/rYYKZ5Lgprivate: System::Void goButton_Click(System::Object^ sender, System::EventArgs^ e)
{
int i(0);
while(true)
{
i++;
theTextBox->Text = Convert::ToString(i);
mf->Refresh();
}
}
A gui is event driven. I.e. there is an event loop that processes/dispatches the messages. goButton_Click(...) was called due to an event. mf->Refresh(); places an event in the event queue.
When you have an infinite loop within an event, the event loop stucks. No event will be processed nor dispatched. Your gui freezes.
If you want some continuous output you need a timer event for each change (you shouldn't need to call Refresh()):