Add MaxCharactersAllowed property to TextBox same as MaxLength
Hi,
In my project I set max char allowed for TextBox using following
TextBox.MaxLength = 20;
I want add one more property as MaxCharactersAllowed. This will work same as MaxLength
TextBox.MaxCharactersAllowed = 20;
I found that TextBox properties written in "System.Windows.Controls.TextBox.cs"
Any idea how to add property?
- Thanks
Re: Add MaxCharactersAllowed property to TextBox same as MaxLength
Question :
Why do you want to make a Property that does the same thing ?
1st solution (easy way) :
Manage the keydown event and check how many characters are inside the textbox, if more discard any new
2nd solution (hard way)
extend your controls properties (Check class extensions)
http://forums.codeguru.com/showthrea...neric-Control&
Re: Add MaxCharactersAllowed property to TextBox same as MaxLength
I would create a new user control inherited from TextBox, add the new property, and add a function to handle the key press event. Then create a delagate to point to the keypress handler function and use the delagate to register the keypressefvent of the the TextBox to the key press event handler.
Re: Add MaxCharactersAllowed property to TextBox same as MaxLength
In my idead you could create your custom control and then listen for Windows event messages passed to your application.
http://msdn.microsoft.com/en-us/libr...l.wndproc.aspx
Not sure if that helps