Hi, I'm having a hard time trying to figure out this: I have a program which has two forms: mainForm and statsForm. I collect data in the main form through buttons and then I click on the statsButton and the statsForm opens. The thing is: If I click the statsButton, the statsForm opens up with updated data, but if I leave it open and continues to use the mainForm, it does not update the labels in the statsForm. It is suppose to update, refresh or whatever every 5 seconds. I've tried this:
public StatsForm()
{
InitializeComponent();
RefreshTimer.Interval = 1000 * 1; //5 seconds
RefreshTimer.Tick += new EventHandler(RefreshTimer_Tick);
RefreshTimer.Enabled = true;
}
private void RefreshTimer_Tick(object sender, EventArgs e)
{
this.Refresh();
}
I tried update, Invalidate and it does not work. I checked and the variables within the statsForm update its values but it does not update update the label assigned to it. How can I make it work?
Loading
Sam HobbsPosted Nov 24, 2011, 12:37 AM
To do the update, you essentially need to re-execute (or do the equivalent of) "statsForm.AceSet1Player1 = aceSet1Player1;" and the other lines. I assume (and if I am wrong then you still have not provided essential information) that you expect "this.Refresh();" to do that. The Refresh will simply use the current value of the data that is in that instance of statsForm; it will not get the data from mainForm.
So what I would do is to do the update of the data in mainForm. You can put "statsForm.AceSet1Player1 = aceSet1Player1;" and related lines in a public function in statsForm and then call that function from mainForm. I assume that there is something that mainForm is doing to update the data that is in it and I would call the update function from there instead of using a timer. There are alternatives for doing what you are doing but I think this is the best balance of simplicity for you as a beginner and use of object-oriented design.
Fabio SantosPosted Nov 23, 2011, 10:05 PM
Then I give the variables in the statsForm, the same name as in the mainForm. Got it?
Ah, one more thing, I tried using textBox instead of labels and the result was the same.
I really appreciate your help!!!
Thanks!
Sam HobbsPosted Nov 23, 2011, 2:34 PM
You don't tell us what variables are used for the data in terms of where they are. You don't tell us how the data is put into the statsForm. You need to tell us more.