Assembly: CleanCode (in CleanCode.dll) Version: 1.2.3.0 (1.2.03)
Parameters
- targetForm
- Type: System.Windows.Forms Form
The target form.
- parentRelativeLocation
- Type: System.Drawing Point
The relative offset from the base form.
- xOffset
- Type: System Int32
An additional fixed x offset.
- yOffset
- Type: System Int32
An additional fixed y offset.
One can set the location relative to a specific parent control of a form or, by passing parentRelativeLocation as (0, 0), relative just to a form. The parentRelativeLocation is typically the Location property of the control displaying the subform, or it may be the Location property of one of its parents--and not necessarily the immediate parent.
A typical usage of this method is inside your subform class. Override the OnVisibleChanged method so that just as the form is being displayed you set its position. That way, the current monitor showing the application will always be the monitor the subform is displayed on. Just before you display the subform with Show or ShowDialog you should set the standard Form.Owner property and optionally the custom ParentRelativeLocation property.
public Point ParentRelativeLocation { get; set; } protected override void OnVisibleChanged(EventArgs e) { if (Visible) { WindowRestorer.SetSubWindowRelativeLocation( this, Owner, ParentRelativeLocation, 20, 50); } base.OnVisibleChanged(e); }
Note that this method is used quite independently of other methods in this class but it is in this class due to being close conceptually.