Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi! I am creating a custom TextBox Control, where I will give it a custom, non-editable Maximum Length. (2147483647 is the custom MaxLength)

Basically, I need to completely remove the MaxLength Property, and replace it with my own MaxLength.

I just don't know how to remove the MaxLength and replace it with my Maximum Length Property.

What I have tried:

private int length = 2147483647;

        [Browsable(true)]
        [Category("Custom Behavior")]
        [Description("The maximum length for the control. This is a read-only property.")]
        [DisplayName("Maximum Length")]

        public int MaximumLength
        {
            get { return this.length; }
        }
Posted
Updated 11-Feb-20 2:50am

You can't, not unless you create an entirely new TextBox-like control form a UserControl and allow am much, much larger-than-standard Length.

But it's not a good idea, even if you could (or you go to all the effort involved in "rolling your own" TextBox).
Think about it: 2,147,483,647 characters is around 27,000,000 lines of text. Do you seriously intend to slap that much text down in front of the user and say "right - you get on with it"? The system will probably slow to a crawl - assuming it doesn't just stop entirely - and your user will have no good way to even read it. I can get around 110 lines of text on my screen at a comfortable reading size, so you are looking at around 250,000 pages of text in a single control, assuming it fills the screen. Just how big do you think the scroll bar tab is going to be? how long will it take the user to wade through that lot looking for the one page - or worse one line - he is looking for?

It's a dumb idea: your users will hate it and by extension your app and you. Sit down, and rethink your entire UI for a user perspective rather than "easy for me to code" - it's completely broken at present.
 
Share this answer
 
Comments
The Magical Magikarp 11-Feb-20 2:15am    
Well, I have a 'Find' and 'Replace' option, which would allow them to find the text they wish & replace it.. It also allows them to travel to the selected line. (Which is organized by pages) So, the answer is No?
johannesnestler 11-Feb-20 10:04am    
So implement exactly that. Persist the "string" - it should be a file. Show the user the search results from the file, let them replace/jump (Maybe get an inspiration from Notepad++ "search and replace in multiple files" feature). Make a Control to show the changed lines (whatever). But DON'T load the whole text to a Control. Only think about memory consumtion (and everything OriginalGriff mentioned). Really rethink what you want to do, The feature can't be "I show you now million lines of text).
I did a Trace-Viewer back than (full verbosity Level the application (backend/frontend) generated About 400k lines of trace for a single click), that worked like that. But not for a second I thought: Ah I just load the whole thing....
The Magical Magikarp 11-Feb-20 2:18am    
Also, could you point me in the right direction for creating my own entirely new TextBox from a UserControl? Thanks :)
Why would you want to do this? The existing MaxLength of the TextBox also reflects the actual maximum length of a string in bytes. You can't make a MaxLength property larger and have it work. You can't create a string bigger than Int32.MaxValue bytes or characters in length. So, what's the point?
 
Share this answer
 
Technically, by inheriting TextBox, you can shadow its MaxLength property with the new keyword:
C#
public class CustomTextBox : TextBox
{
   public new int MaxLength
   {
      get { /* ... */ }
   }
}
If you do not provide any setter, the new property will be read-only.

But, as Paul stated in its solution, that is a terrible idea to try to stuff so much information in a single control.
 
Share this answer
 
v2
Comments
The Magical Magikarp 11-Feb-20 21:15pm    
I liked the other answers, but yours answers my question perfectly :) Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900