How to create user control with multiple controls?

  • Thread starter Thread starter Brian
  • Start date Start date
B

Brian

Hi, All,
I want to create a single user control (component) with
multi-controls. for example, I want to use one button
control and 2 listBox controls to build one single user
control. so, user can directely use the user control
instead of 3 controls. They can click button to move the
selected item from one listbox to another. but how can I
inherit these 3 controls? And also, once I create the
single user control, I can not implement the methods or
events like "Click" by cliking the button, because all
the 3 controls are integrate to a single unit once user
try to use it. I didn't find any example using google.

Any suggestion?
Thanks and have a one

Brian
 
Brian said:
I want to create a single user control (component) with
multi-controls. for example, I want to use one button
control and 2 listBox controls to build one single user
control. so, user can directely use the user control
instead of 3 controls. They can click button to move the
selected item from one listbox to another. but how can I
inherit these 3 controls?

Simply choose "Project" -> "Add usercontrol...". In the designer, place the
controls on the usercontrol.
And also, once I create the single user control, I can
not implement the methods or events like "Click" by
cliking the button, because all the 3 controls are integrate
to a single unit once user try to use it.

Add handlers to the relevant events of all controls on the usercontrol and
call the appropriate 'MyBase.On<event name>' method of the usercontrol to
raise the event as an event of the usercontrol.
 
Herfried,
Thanks for your help, but I still have a few questions.
First, In my user control, it should be "Inherits
System.Windows.Forms.UserControl" or something else?

Second, If I have a click event like,Public Overridable
Sub cmdAssign_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles cmdAssign.Click on user
control. How can I call the myBase.onCmdAssign_Click( the
one you tell me 'MyBase.On<event name>' method ) when I
implement?

I'm new to .Net, could you give me more detail?

Thanks lot and really appreciate your help

Brian
 
Brian,

Brian said:
First, In my user control, it should be "Inherits
System.Windows.Forms.UserControl" or something else?

Yes, you should inherit from 'UserControl', otherwise you won't be able to
create a composite control in the designer.
Second, If I have a click event like,Public Overridable
Sub cmdAssign_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles cmdAssign.Click on user
control. How can I call the myBase.onCmdAssign_Click( the
one you tell me 'MyBase.On<event name>' method ) when I
implement?

Call 'MyBase.OnClick(...)' in all controls' 'Click' event handlers in order
to raise a single click event for the whole usercontrol if any of the
controls is clicked.
 

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