SIGN UP MEMBER LOGIN:    
ARTICLE

Create User Defined Controls in C#

Posted by Vilas Gite Articles | C# Language May 05, 2011
In this article you will learn how to create User Defined Controls in C#.
Reader Level:


Let's create a User Control.

Start Visual Studio 2005.

File -New-Project Type Visual C#.

User1.gif

Select Windows Control Library from the Templates.

Specify Name with NumericTextBox and save on proper location.

Visual Studio Opens with Blank Control.

User2.gif

Right Click on Blank Control and View Code

User3.gif

Inherit TextBox control by modifying System.Windows.Forms.TextBox on UserControl.

Add code in control to restrict for non-numeric input by user.

User4.gif

Open UserControl1.Designer.cs from Solution Explorer and pass a comment to the line, shown in below:

User5.gif

Now, Build – Build NumericTextBox.

Build Succeeded.

How to use a user defined control, such as the NumericTextBox, in a Windows application.

Create a Windows application with the name PhoneDictionary.

User6.gif

Select a ToolBox and right-click on All Windows Forms then click on Choose items.

.NET Framework Components by default shown after Choose Items...

User7.gif
 
Now, browse to the location where NumericTextBox.dll has been saved; select NumericTextBox.dll, click the open button and to close choose Toolbox Items.

User8.gif

Add the User Control to the form.

User9.gif

Click on Start Debugging or press F5.

User10.gif

Only numeric input has been accepted in the textbox shown (NumericTextBox). The User Control can be used many more times in an application/project in Visual Studio.

Login to add your contents and source code to this article
share this article :
post comment
 

This article is very usful. Please tell me how to bring the decimal numbers(Ex : 1234.56) in the user defined edit box?

Posted by mani kandan Mar 15, 2012
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Team Foundation Server Hosting
Become a Sponsor