Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Parent Form ->
- Child Control 1 ->
- Child Control 2 ->
- Custom Control
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- _originalParent = Parent; // member var
- _originalLocation = Location; // member var
- }
- protected void SetParentToRoot()
- {
- var p = Parent;
- if (p == null) return;
- while ((p?.Parent ?? null) != null)
- p = p.Parent;
- Parent = p; // this line will cause the app to hang
- // determine the screen location of the control based on the original parent
- var screenPoint = _originalParent.PointToScreen(_originalLocation);
- // set location
- Location = p.PointToClient(screenPoint);
- }
- protected void RestoreParent()
- {
- Parent = _originalParent;
- Location = _originalLocation;
- }
Add Comment
Please, Sign In to add comment