Adding controls to a dynamic form?

  • Thread starter Thread starter Connor T
  • Start date Start date
C

Connor T

Hi,

I posted this a while back, and got a solution but it didnt work.

The question was:

I have a form which is dynamically generated from the contents of a Database
using commands such as this:

hostform.Controls.Add(aRadio)
However, that adds the control to the top level window. I want to add them
to a panel i've created so that can do the scrolling

And the answer was:

\\\
hostform.Panel1.Controls.Add(aRadio)
///

(Assuming that the control's modifier is set to 'Friend'/'Public'/...)

However that doesnt compile.

It gives "Panel1 is not a member of System.Windows.Forms.Form

How can I fix this?

Panel1 is marked as Public...

Rgds,
Dan
 
If Panel1 is public, then just remove the "hostform" from your line...

Panel1.Controls.Add(aRadio)
or
Me.Panel1.Controls.Add(aRadio)

Try that.

Chris
 
Afraid that still doesnt work, it says Panel1 not declared.

I think the problem is that my Radio class is in a separate source file to
the form in question, could that be it? Can't i work around this

Perhaps I can pass a reference to Panel1 itself into the constructor for my
Radio class?

Rgds,
Dan
 
I should also add, that I have this:

Public Sub New(ByVal host As System.Windows.Forms.Form)

hostform = host

End Sub



Maybe i can alter that some way?
 
Ah, I think that answered my question!

I pass in System.Windows.Forms.Panel instead, and reference Panel1!

Thanks all! It's proved this is really an odd thing i'm doing!!

Rgds,
Dan
 

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

Back
Top