CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2011
    Posts
    8

    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

  2. #2
    Join Date
    Feb 2012
    Location
    Strasbourg, France
    Posts
    116

    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&

  3. #3
    Join Date
    Jan 2002
    Posts
    195

    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.

  4. #4
    Join Date
    Feb 2012
    Location
    Strasbourg, France
    Posts
    116

    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
  •  





Click Here to Expand Forum to Full Width

Featured