From http://www.cnblogs.com/freeliver54/archive/2008/09/28/1301431.html
Generally, buttons are not used as user controls.
Because the button itself can meet our general needs
Make buttons into user controls
It is for our developmentProgramYou can perform similar operations on a batch of buttons.
For example, verify a permission to change a skin.
This example only provides the simplest button effect.
1. Open vs to create a Windows application project winformstudy
In the new solution, add the Windows control library project usercontrolstudy.
2. Design view in usercontrol1
Add a button button1
3. Modify the dock attribute of button1 to fill
Make it change with the control size
4. Publish text settings for buttons
Public String ucbuttontext
{
Set
{
This. button1.text = value;
}
Get
{
Return this. button1.text;
}
}
5. Publish the corresponding click of the button
It calls the Click Event of the control triggered when the control is used.
Double-click button1 to enterCodeWrite
Private void button#click (Object sender, eventargs E)
{
// MessageBox. Show ("button1 ");
Base. onclick (E );
}
6. Compile and use this button user control in form1 of winformstudy
Go to the design view of form1
The usercontrolstudy tab is displayed in the toolbox.
And its usercontrol1 is the button user control we just compiled.
Drag the control to modify the ucbuttontext attribute.
And write the Click Event of the control.
Private void usercontrol11_click (Object sender, eventargs E)
{
MessageBox. Show ("winfrom ");
}
7. Generate and run winformstudy to view the form1 button Effect