C # winform simple button user control example

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.