Reputation: 2748
I have a form with a timer.The timer loads a dialog to show that the form is busy. When the main form does not have focus, the busy form is loaded in the top left of the pc screen (Which is not expected). When the form has focus it works as expected. If set ShowInTaskbar to true then it does work as expected even when the main form does not have focus. What is going on here and how can i fix ?
C# Code
namespace CenterParentIssue
{
public partial class Main : Form
{
WaitingForm formWindowsWaitingForm;
public Main()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
formWindowsWaitingForm = new WaitingForm();
formWindowsWaitingForm.StartPosition = FormStartPosition.CenterParent;
formWindowsWaitingForm.ShowInTaskbar = false;
formWindowsWaitingForm.ShowDialog();
}
}
}
Upvotes: 0
Views: 549
Reputation: 4230
You need to give the WaitingForm
a parent context. ShowDialog()
has an overload which takes a Window as an argument, this window is the parent/owner.
//...
formWindowsWaitingForm.ShowDialog(this);
//...
Upvotes: 2