Programs | controls using user controls in. NET Applications
Zhengzo 2004-11-30
People who have done asp.net know that it is convenient to use user controls when developing, providing considerable flexibility for functional modularity. Happily, you can also use user controls to develop Windows Forms. Here we take a look at adding properties and events to the user control and implementing sending the message to the parent container. This article is mainly to provide some references for friends who have not used the user control.
The implementation of the user control is relatively simple, directly from the System.Windows.Forms.UserControl.
public class UserControl1:System.Windows.Forms.UserControl
To facilitate the test I added a TextBox above and registered the TextChanged event for the textbox,
This.textBox1.TextChanged + = new System.EventHandler (this.textbox1_textchanged);
MessageBox.Show ("The value of the current control is:" + e.message);
}
}
}
In addition to dynamic loading, the control is added to the container's Controls collection, and the following is the addition of controls to the constructor.
Public Form1 ()
{
InitializeComponent ();
UserControl1 UC = new UserControl1 ();
Uc. Customvalue = "Dynamically loaded user control";
Uc. Usercontrolvaluechanged + = new Textboxchangedhandle (usercontrol11_usercontrolvaluechanged);
This. Controls.Add (UC);
}
In addition, drag the user control from the Toolbox in vs.net to the form, and if it is the first time you need to compile the project.
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.