Interface / Reflection Question

D

Doug Handler

I have an interface called IChannel that has a series of items including a
delcaration for a Panel. I have a class called Channel that implements
IChannel. I'm wanting to dynamically load each channel at runtime. So, i
have a CustomerChannel that inherits Channel and it is bound at runtime and
everything i want to do happen happens.

My constructor for CustomerChannel looks like this:
CustomerChannel() : base("Customer");

This works fine!! However, now i need to have each channel that is created
and loaded dynamically to "supply" a panel of controls so that it can be
"added" to the navigation bar at runtime. My question is this: How do I
"pass" or "assign" this panel so that the main application loads it.

IChannel looks like this:

string Name {get; set; }
Panel NavPanel {get; set; }

How do i get this Panel into my main application? I hope my question makes
sense.

Thanks in advance.
Doug
 
L

Larry Lard

Doug said:
I have an interface called IChannel that has a series of items including a
delcaration for a Panel. I have a class called Channel that implements
IChannel. I'm wanting to dynamically load each channel at runtime. So, i
have a CustomerChannel that inherits Channel and it is bound at runtime and
everything i want to do happen happens.

My constructor for CustomerChannel looks like this:
CustomerChannel() : base("Customer");

This works fine!! However, now i need to have each channel that is created
and loaded dynamically to "supply" a panel of controls so that it can be
"added" to the navigation bar at runtime. My question is this: How do I
"pass" or "assign" this panel so that the main application loads it.

IChannel looks like this:

string Name {get; set; }
Panel NavPanel {get; set; }

How do i get this Panel into my main application? I hope my question makes
sense.

I don't think you need any reflection here (which is good, because it's
no fun). To give you an idea what to do, create a plain winforms app,
drop a Panel on the form, and look at the autogenerated code. That will
show you how to get a Panel onto your form, once you have one. And
getting a Panel from a Channel is easy:

CustomerChannel myChannel = new CustomerChannel();
Panel channelpanel = ((IChannel)myChannel).NavPanel;
// now stuff that puts channelpanel into the actual UI container

Simple as that?
 
B

Bruce Wood

Easy: just set the position and size of the panel (via its properties),
then add it to the Controls collection of your main form:

mainForm.Controls.Add(generatedPanel);

and it will appear after the method that does the Add completes.
 

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