Monday, March 21, 2011

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...
developercode
About the Author
Sayyad is a Software Engineer, Blogger and Founder of Developers Code from India.His articles mainly focus on .Net (Web and Windows based applications), Mobile Technologies (Android,IPhone,BlackBerry) and SEO.

Labels: , , , , ,

6 Comments:

At March 21, 2011 at 7:39 PM , Blogger Dotnet Tutorials said...

Nice post Again......For Beginners

 
At April 15, 2011 at 2:26 PM , Anonymous Anonymous said...

Thanks for sharing

 
At April 15, 2011 at 2:26 PM , Anonymous Anonymous said...

hi taanu keep going....

 
At June 28, 2011 at 10:17 AM , Anonymous Anonymous said...

Thanks for sharing

 
At June 28, 2011 at 10:17 AM , Anonymous Dotnet Tutorials said...

Nice post Again......For Beginners

 
At August 12, 2011 at 11:38 AM , Anonymous Anonymous said...

Vow..its working......pls post these type of articles on custom controls.......

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home