C #. NET encapsulate custom components (Controls) Dll

Source: Internet
Author: User

C #. NET encapsulate custom components (Controls) Dll

It is very easy to encapsulate custom controls with no technical content. Here we will summarize the examples of encapsulating custom digital text boxes:


[1] create a custom Control Library-Windows Forms Control Library




[2] Add a custom Component-Component Class




[3] inherit TextBox and add a KeyPress event. The Code is as follows:

Using System; using System. collections. generic; using System. componentModel; using System. diagnostics; using System. linq; using System. text; using System. windows. forms; namespace WinForms. selfControl {////// Numeric text box -- if the generated Dll cannot be imported in the toolbox, you can drag the Dll directly ///Public partial class TextBoxNumber: TextBox {public TextBoxNumber () {InitializeComponent ();} public TextBoxNumber (IContainer container) {container. add (this); InitializeComponent (); this. keyPress + = TextBoxNumber_KeyPress ;}////// Only numbers can be entered ///Void TextBoxNumber_KeyPress (object sender, KeyPressEventArgs e) {// if the input is neither a numeric key nor a carriage return or Backspace key, cancel the input if (! (Char. IsNumber (e. KeyChar) & e. KeyChar! = (Char) 13 & e. KeyChar! = (Char) 8) {e. Handled = true ;}}}}

[4] Add the generated Dll to the toolbox




[5] test the custom control to verify that only numbers can be entered




[6] Notes

It must be compiled using AnyCPU. If the generated Dll is imported into the toolbox, you can drag the file directly...


Source code:

Http://download.csdn.net/detail/aoshilang2249/8172891




Related Article

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.