well i have a form that i open using ShowDialog(this).
i try to change the position of the form using its Location property, but i dont understand this position is relative to what exactly?
i want to open this form below a certain button.
so how can this be done?
thanks
views:
9answers:
1
+1
A:
A Form will expect the co-ordinates relative to the screen’s top-left corner. However, the location of a Control within a Form is relative to the top-left corner of the form†.
Use the Control’s Location
property to find its location, and then call PointToScreen
on the Form object to turn it into screen co-ordinates. Then you can position the new form relative to that.
For example:
var locationInForm = myControl.Location;
var locationOnScreen = mainForm.PointToScreen(locationInForm);
using (var model = new ModelForm())
{
model.Location = locationOnScreen + myControl.Height + 3;
model.ShowDialog();
}
† Actually the top-left corner of the client area of the form.
Timwi
2010-08-22 04:29:49