protected void CenterToParent() {
Control ctl;
int w;
int h;
// MS creates the handle here.
if (TopLevel) {
if (!IsHandleCreated)
CreateHandle ();
}
if (Width > 0) {
w = Width;
} else {
w = DefaultSize.Width;
}
if (Height > 0) {
h = Height;
} else {
h = DefaultSize.Height;
}
ctl = null;
if (Parent != null) {
ctl = Parent;
} else if (owner != null) {
ctl = owner;
}
if (owner != null) {
this.Location = new Point(ctl.Left + ctl.Width / 2 - w /2, ctl.Top + ctl.Height / 2 - h / 2);
}
}