Develop your own TextBox with a new enumerated property called as Input Type
Hi Friends,In this tutorial i wolud like to explian very interesting topic about creating your own Textbox.Here we are creating two types of text boxes .one Textbox for accepting only digits and another textbox accepting only alphabets(Upper case and lower case)
Step 1)First open the visual studio 2008
Step 2)Next open the windows forms control library project and change the name as UserDefinedTextBox
Step 3)next open the code view
Step 4)change the class declaration as follows
public partial class userControl:TextBox
Step 5)Next open the design mode and change the properties and set the name as MyOwnTextBox
Step 6)Next,write the code
public enum Test { Integral; Alphabets; } Test t;//creating a variable for enum public Test InputType { set { t=value; } get { return t; } }
Step 7)Next write the code for Key press event
MyOwnTextBox_KeyPressEvent { if(t==Test.Integral) { if(e.Keychar>='0' && e.keychar<='g') { e.handled=false;//keystroke accepted } else { e.handled=true;//cancel the keystroke } }//if end if(t==Test.Alphabets) { if(e.Keychar>='A' && e.keychar<='Z' || e.Keychar>='a' && e.keychar<='z') { e.handled=false;//keystroke accepted } else { e.handled=true;//cancel the keystroke } }//if end }
Step 8)Next build the project
step 9)Succefully your UserDefinedTextBox.dll is created.it is located in the E:\Project\UserDefinedTextBox\Bin\debug folder with control named MyOwnTextBox
step 10)next we have to Test that textbox control for this...follow the steps
step 11)First open the visual studio 2008
Step 12)Next open the windows Applcation project and change the name as TestTextBox
Step 13)next,Drag and drop the UserDefinedTextBox.dll in to toolbox
Step 14)a new control MyOwnTextBox is added
That's it...
Labels: .Net Tutorials, Aspnet, C#, CSharp, Custom Controls, Tanisha
6 Comments:
Nice post Again......For Beginners
Thanks for sharing
hi taanu keep going....
Thanks for sharing
Nice post Again......For Beginners
Vow..its working......pls post these type of articles on custom controls.......
Post a Comment
Subscribe to Post Comments [Atom]
<< Home