Return Owner from Sender Object
Hi all,
I'm trying to dynamically retrieve the owner of a sender object.
Let's say I have Form1, Form2, Button1 and Button2.
I click Button1 on Form1 which Creates a New Form2 with Button2
On creation, I want to dynamically AddHandler of Button2 which Shows a MessageBox with the Name of Form2.
I've sorted everything so far apart from how to get this information back
Essentially, in reality, I suppose all I'm trying to do is add the handler of msgbox(me.name) to Button2
Does anyone have any ideas?
Thanks
Re: Return Owner from Sender Object
This all sounds very contrived. What are you actually trying to achieve?
Ignoring for the moment that what you describe doesn't really appear to achieve anything useful, are you saying that you want a method in Form1 to handle the Click event of a Button on Form2?
Re: Return Owner from Sender Object
Assuming sender is a UI control, you can ask it for its parent form. See here.
DirectCast(sender, Control).TopLevelControl
something like that