-
June 25th, 2012, 03:49 AM
#1
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
-
June 26th, 2012, 03:23 AM
#2
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&
-
June 26th, 2012, 09:31 AM
#3
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.
-
June 27th, 2012, 03:44 AM
#4
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|