I create a new form and call from the parent form as follows:
loginForm = new SubLogin();
loginForm.Show();
I need to display the chi
If any windows form(child form) is been opened from a new thread of Main window(parent form) then its not possible to hold the sub window to the center of main window hence we need to fix the position of the sub window manually by means of X and Y co-ordinates.
In the properties of Subwindow change the "StartPosition" to be "Manual"
private void SomeFunction()
{
Thread m_Thread = new Thread(LoadingUIForm);
m_Thread.Start();
OtherParallelFunction();
m_Thread.Abort();
}
private void LoadingUIForm()
{
m_LoadingWindow = new LoadingForm(this);
m_LoadingWindow.ShowDialog();
}
public LoadingForm(Control m_Parent)
{
InitializeComponent();
this.Location = new Point( m_Parent.Location.X+(m_Parent.Size.Width/2)-(this.Size.Width/2),
m_Parent.Location.Y+(m_Parent.Size.Height/2)-(this.Size.Height/2)
);
}
Here the co-ordinates of center of parent is calculated as well as the subwindow is kept exactly at the center of the parent by calculating its own center by (this.height/2) and (this.width/2) this function can be further taken for parent relocated events also.