Controls added at runtime??

A

Able

Dear friends

I have to forms, frm1 and frm2. In frm1 its Button1 and TextBox1. In runtime
when clicking on Button1 a button is created on frm2 like this:

Dim myfrm2 as New frm2
Dim bt As New Button
AddHandler bt.Click, AddressOf myButton_Click
myfrm2.Controls.Add(bt)

In Module1 the myButton_Click event is like this:

Public Sub myButton_Click(ByVal sender As System.Object, ByVal e As
System.EventsArgs)

'Doe something'

End Sub

My goal is to print "Hello" in TextBox1 in frm1 when fiering the
myButton_Click event, but I cant figure out how.


Regards Able
 
A

Armin Zingler

Able said:
Dear friends

I have to forms, frm1 and frm2. In frm1 its Button1 and TextBox1. In
runtime when clicking on Button1 a button is created on frm2 like
this:

Dim myfrm2 as New frm2
Dim bt As New Button
AddHandler bt.Click, AddressOf myButton_Click
myfrm2.Controls.Add(bt)

In Module1 the myButton_Click event is like this:

Public Sub myButton_Click(ByVal sender As System.Object, ByVal e
As System.EventsArgs)

'Doe something'

End Sub

My goal is to print "Hello" in TextBox1 in frm1 when fiering the
myButton_Click event, but I cant figure out how.


IMO this is bad design. Why use a module? Why not handle the event within
frm1? In frm1 you would have access to the textbox.
 
A

Able

In my county we have a saying like this:

"You dont see the wood because of all the trees."

Thanks Armin

Able
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top