Guest User

Untitled

a guest
Dec 11th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. Parent Form ->
  2. Child Control 1 ->
  3. Child Control 2 ->
  4. Custom Control
  5.  
  6. protected override void OnLoad(EventArgs e)
  7. {
  8. base.OnLoad(e);
  9.  
  10. _originalParent = Parent; // member var
  11. _originalLocation = Location; // member var
  12. }
  13.  
  14. protected void SetParentToRoot()
  15. {
  16. var p = Parent;
  17. if (p == null) return;
  18. while ((p?.Parent ?? null) != null)
  19. p = p.Parent;
  20.  
  21. Parent = p; // this line will cause the app to hang
  22.  
  23. // determine the screen location of the control based on the original parent
  24. var screenPoint = _originalParent.PointToScreen(_originalLocation);
  25.  
  26. // set location
  27. Location = p.PointToClient(screenPoint);
  28. }
  29.  
  30. protected void RestoreParent()
  31. {
  32. Parent = _originalParent;
  33. Location = _originalLocation;
  34. }
Add Comment
Please, Sign In to add comment