OnClick from UserControl Button

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi There

Another dumb newbie question, sorry. I want to be able to create
applications by dragging my own version of controls onto a Form. The reason
for making say a button as a user control, is I want to button color to be a
specific color and not the default color. When I drag the Usercontrol onto
the form it all looks fine, but when it executes, the onclick can't be set on
the usercontrol. I'm guessing the OnClick on the button needs to send an
event to theUserControl so I can get at the onclick event in the designer.

Is there a better way to do this?

If this is the best way to do this, do I need to propergate all the possible
actions of the control up to the UserControl?

Thanks
Dave
 
So you just want to change the default color of a Button but allow this
control to be reusable from the ToolBox? If so, then you should derive your
control directly from the Button class and not from UserControl.
 
Hi Tim

I changed the class to be derived from Button instead of UserControl, but
there are obviously some other things that need to be changed. Starting with
a UserControl doesn't seem the best way, but the only other UI option seems
to be a Form, so now I'm confussed! Any examples you know of that would
explain the procedure to a dumbass newbie would be appreciated.

Thanks
Dave
 
A UserControl is a composite control. This means that the control is usually
exposed as other controls simply grouped together. So the reason that you
have a designer view of the UserControl is to allow you to easily drag and
drop controls from the ToolBox. In your case, you just want to modify the
default behavior of a single control. So the best approach would be to just
inherit directly from this control. The main benefit is that all the events
and properties of the Button will be directly exposed through your custom
control since they are inherited. The quick start tutorial, linked below,
has some useful information on getting started building custom controls.
http://samples.gotdotnet.com/quickstart/winforms/doc/WinFormsCreatingControls.aspx
 
Hi Tim

That was exactly what I needed! Thankyou

You wouldn't be interested in looking at another thread I have going called
"Form component like common Openfiledialog"?

Thanks again
Dave
 
Back
Top