Posted on 2004-08-04
One recurrent problem I’m having is making the program do sequential tasks. In VB.NET the only way I found to stop the program in the middle of a subroutine in Form1 is to call Form2 through Form2.ShowDialog(), have the program do whatever necessary and then have it return back to Form1. Whatever values the variables acquire in Form2 are passed to Form1 through dimming the variables on a Modular level. This modal dialog seems to work well.
Here in Visual C++ .NET it seems the problems in this respect are not lesser. Suppose the following situation. First, I need to press a button which will cause opening of OpenFileDialog, so I write something like this:
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
<code to open a text file and place its contents into two arrays>
Then, only after finishing the job of choosing the text file and placing data contained in that text file in arrays, I need to have the data in these arrays plotted on the form. Thus, as a next step I need to invoke the following:
void OnPaint( PaintEventArgs *paintEvent )
<some code plotting the data on the screen>
Unfortunately, when I have both functions in the same form Form1.h, both of them are executed at the same time. My impression was that one function can call another function but in this case obviously the method OnPaint seems to be common also with the operations that depict the buttons themselves – all buttons appear at the same time, so does the plotting of whatever is to be plotted by calling the OnPaint function.
What can I do to make clicking and opening the text file occur prior to plotting the data from that file?