By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,030 Members | 2,277 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,030 IT Pros & Developers. It's quick & easy.

How to create user control with multiple controls?

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Brian" <an*******@discussions.microsoft.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2

P: n/a
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
Add handlers to the relevant events of all controls on the usercontrol andcall the appropriate 'MyBase.On<event name>' method of the usercontrol toraise the event as an event of the usercontrol.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

.

Nov 21 '05 #3

P: n/a
Brian,

"Brian" <an*******@discussions.microsoft.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.