How to Set Location of Mdichild at center of MdiParent
I tried to set location of a modeless Form of a MdiChild (ShippingDialog ) at the center of its MdiParent (CreateOrderView.MdiParent) with below code.
The horizontal (X) value of MdiChild is only little bit off while vertical (Y) value of MdiChild is totally off. I expected 5.4 centimeters while I got 9.7 centimeters between Top of the MdiChild and MdiParent. Any idea what I am missing here?
Code:
if(ShippingDialog != null)
{
// set MdiParent and location for new dialog only
if (newDialog == true)
{
// Set EquipmentShippingAddress inside of MdiParent (CallManager)
ShippingDialog.MdiParent = CreateOrderView.MdiParent;
// Manually set EquipmentShippingAddress at center of MdiParent (CallManager)
ShippingDialog.StartPosition = FormStartPosition.Manual;
ShippingDialog.Location = new System.Drawing.Point(ShippingDialog.MdiParent.Location.X + (ShippingDialog.MdiParent.Width - ShippingDialog.Width) / 2, ShippingDialog.MdiParent.Location.Y + (ShippingDialog.MdiParent.Height - ShippingDialog.Height) / 2);
}
ShippingDialog.Show();
ShippingDialog.BringToFront();
}
thanks in advance,
Xiaoming
There is one absolute truth that there is no such thing as absolute truth.