So I am making a small Program where I have a UserControl inside a tab control. And i am trying to find out how to go back up a level from inside the user control to add tabs to the tab control.
Asked
Active
Viewed 511 times
-1
-
is this winform or wpf? – Carbine Mar 21 '16 at 00:33
-
This should help - http://stackoverflow.com/questions/8820606/get-access-to-parent-control-from-user-control-c-sharp – Carbine Mar 21 '16 at 00:34
-
3Just don't, a control should never monkey with its container. Raise an event instead, the form can take care of it. – Hans Passant Mar 21 '16 at 00:36
1 Answers
-1
Okay Thanks for the comment, I figured it out, the link posted by CarbineCoder had the following code
Form parentForm = (this.Parent as Form);
This is the code i was trying to use but what was actually needed was
Form parentForm = (this.Parent.Parent as Form);

Lazurus
- 67
- 1
- 8
-
Well, that makes no sense. The Parent of the user control is the TabPage. The parent of the tab page is the TabControl. That's not a Form. Don't do this at all, it is wrong. – Hans Passant Mar 21 '16 at 00:50
-