tags:

views:

253

answers:

2

I have a Windows form from which I would like to open a status form that says "Saving..." and then disapears when the saving is complete. I would like to center this small status form in the middle of the calling form. I've tried setting the "StartPosition" propery to "CenterParent", but it doest work. I create the status form from the other form like so:

SavingForm saving = new SavingForm();
savingForm.Show();
Thread.Sleep(500); //Someone said this is bad practice ... why?
savingForm.Close();

Wouldn't the calling form be the "Parent"? When I set a watch for saving it says it has no parent.

I tried:

SavingForm saving = new SavingForm();
saving.Parent = this;
savingForm.Show();
Thread.Sleep(500);
savingForm.Close();

and it throws an exception "Top-level control cannot be added to a control."

How do I center this status window in the calling window?

Thanks in advance

+2  A: 

Use this:

saving.Show(this);

To set the Owner when you show the form.

Edit: The ShowDialog() method also has an overload that let's you specify the owner if that is the route you decide to go:

saving.ShowDialog(this);
Cory Charlton
+1  A: 

i would do something like this:

SavingForm saving = new SavingForm(this);
savingForm.ShowDialog();

In SavingForm i would start a timer in the load handler that runs for 500 milliseconds and then closes the form when done. Cleaner that way. ShowDialog will also lock your UI to only display the saving form and not allow the user to monkey with anything.

Paul Sasik