So on my main form there are a few labels, which are defined by settings. The user can press an edit button which opens a new form with text boxes and a save button to edit those settings/labels. It works properly, it changes the settings but you only notice the difference if you close then re open the program. How do I make my main form refresh when the user makes the changes?

Main form:
https://gist.github.com/959264

Editing form:
https://gist.github.com/959265

Thanks

Anyone?

Call a function in after the completion of changes and update it accordingly....

Hi,

try
this.Invalidate(); or this.refresh

Hi,

try
this.Invalidate(); or this.refresh

That didn't work, neither refresh or invalidate.

It seems like you trying to set the labels of your workoutMealPlan form in the editMondayMeal form. Nowhere in your code are you actually setting the labels in the workoutMealPlan after you finish editing them.

In your editor form:

private void btn_saveMondayMeals_Click(object sender, EventArgs e)        {            
string mondayMealBreakfast = txtbox_editMondayMealBreakfast.Text;            
//etc...etc...
lbl_editMondayMealSnack2.Refresh();

workoutMealPlan.UpdateLabels();

this.Close();
}

And in the main form:

void UpdateLabels()
{
     lbl_mondayBreakfast.Text = Properties.Settings.Default.mondayBreakfast
     //Etc etc
}

Note that this function can also be called in the main forms constructor to avoid duplicating the code.

Also note, it is generally an unsafe practice to set things such as a control or components properties in a form constructor. Instead, do this stuff in the form's Load event as it will ensure that everything is loaded and ready to go.

One more thing - this isn't a very threadsafe solution, although it will probably never have any issues. It may be worth your while to look into delegates, and invoking delegates from a seperate thread if you plan on using more modeless dialogues in the future (or any kind of multithreading for that matter).

It seems like you trying to set the labels of your workoutMealPlan form in the editMondayMeal form. Nowhere in your code are you actually setting the labels in the workoutMealPlan after you finish editing them.

In your editor form:

private void btn_saveMondayMeals_Click(object sender, EventArgs e)        {            
string mondayMealBreakfast = txtbox_editMondayMealBreakfast.Text;            
//etc...etc...
lbl_editMondayMealSnack2.Refresh();

workoutMealPlan.UpdateLabels();

this.Close();
}

And in the main form:

void UpdateLabels()
{
     lbl_mondayBreakfast.Text = Properties.Settings.Default.mondayBreakfast
     //Etc etc
}

Note that this function can also be called in the main forms constructor to avoid duplicating the code.

Also note, it is generally an unsafe practice to set things such as a control or components properties in a form constructor. Instead, do this stuff in the form's Load event as it will ensure that everything is loaded and ready to go.

One more thing - this isn't a very threadsafe solution, although it will probably never have any issues. It may be worth your while to look into delegates, and invoking delegates from a seperate thread if you plan on using more modeless dialogues in the future (or any kind of multithreading for that matter).

Thanks a lot, I've started looking into threading and delegates. However with what you posted, in my editor form I get an error that System.Windows.Forms can't find a definition for "UpdateLabels".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.