Pirahnaplant
Well-known member
- Joined
- Mar 29, 2009
- Messages
- 75
- Programming Experience
- 3-5
How can a UserControl read from or change its containing form's properties?
John, this is the third or fourth time in the last three weeks you've jumped in with an ulta-easy solution to things here, am I slipping that badly??VB.NET:Me.ParentForm.Text = "test"
ParentForm is a property of ContainControl class, which UserControl class inherits. Panel does not inherit this, it's inheriting ScrollableControl/Control, so it only has the Parent property (type Control). You could go from Parent to Parent until you reach a control of type Form, or as JB suggested pass the reference to the form/control you need access to. As newguy suggested it may be better to raise an event from the control that the consumer of your control can use for it's needs, instead of creating a dependency in your control, it's hard to tell without knowing what you're actually trying to do.When I try that I get an error: "ParentForm is not a member of UserControlName"
Edit: Nevermind, it was because I was inheriting from a Panel.
Really? I don't think soJohn, this is the third or fourth time in the last three weeks you've jumped in with an ulta-easy solution to things here, am I slipping that badly??