T
Tomas Vera
OK. This is something that is probably simple, but has me totally confused.
In all my previous work, whenver I needed on of my custom components I simply
dragged it onto my form and all was well.
But now, I need to develop a form that basically contains a panel into which I
need to dynamically insert one of several components.
On the main form, I have 3 buttons. When the user presses button 1, I need to
put Component1 into the panel on the main form. When The user presses button 2,
component2 will replace component1 on the main form. And so on for button3 (and
however many more buttons I will need).
In the response function for Button1_Click event, I tried this:
private Button1_Click(..)
{
component1 comp1 = new component1(); //<<== badline
mainPanel.Controls.Clear();
mainPanel.Controls.Add(comp1);
}
But, the line that tries to instantiate comp1 gives an "Cant create an instance
of abstract class 'component1'" (or something like that).
I tried removing the work "abstract" from the declaration of component1. And now
I'm able to compile, when the InitializeComponent function runs, the elements in
component1 are null and an exception is thrown when the system tries to assign
handlers for events.
Next, I've tried creating the component's elements in the constructor, and now
InitializeComponent is able to initialize the event handlers. But now, none of
the controls that I have placed on component1 show up on the main page.
How do I create a component (using the designer) that I can instantiate on the
fly?
So far, my only solution is to create the entire component on the fly, but
designing this way takes quite a long time. I need to start a project on Monday,
which has a four week deadline. This project will almost certainly require the
funcitonality that I have mentioned above, but I'm not sure how to get this
done.
As always, all help (ideas) are appreciated!
-tomas
In all my previous work, whenver I needed on of my custom components I simply
dragged it onto my form and all was well.
But now, I need to develop a form that basically contains a panel into which I
need to dynamically insert one of several components.
On the main form, I have 3 buttons. When the user presses button 1, I need to
put Component1 into the panel on the main form. When The user presses button 2,
component2 will replace component1 on the main form. And so on for button3 (and
however many more buttons I will need).
In the response function for Button1_Click event, I tried this:
private Button1_Click(..)
{
component1 comp1 = new component1(); //<<== badline
mainPanel.Controls.Clear();
mainPanel.Controls.Add(comp1);
}
But, the line that tries to instantiate comp1 gives an "Cant create an instance
of abstract class 'component1'" (or something like that).
I tried removing the work "abstract" from the declaration of component1. And now
I'm able to compile, when the InitializeComponent function runs, the elements in
component1 are null and an exception is thrown when the system tries to assign
handlers for events.
Next, I've tried creating the component's elements in the constructor, and now
InitializeComponent is able to initialize the event handlers. But now, none of
the controls that I have placed on component1 show up on the main page.
How do I create a component (using the designer) that I can instantiate on the
fly?
So far, my only solution is to create the entire component on the fly, but
designing this way takes quite a long time. I need to start a project on Monday,
which has a four week deadline. This project will almost certainly require the
funcitonality that I have mentioned above, but I'm not sure how to get this
done.
As always, all help (ideas) are appreciated!
-tomas