We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Limit max number of characters in a line

Hi! I''m using essential edit as a formula editor, so we only limit the editor to have 1 line. When a user type in an extreme number of characters (>32000), the function that clears out the wave lines crashes. It seems to hit an integer limit. Is there a way to limit the number of characters the user can enter. We definitely don''t need 30K chars, but it would be nice not to crash. Thanks.

4 Replies

AD Administrator Syncfusion Team February 3, 2005 03:18 PM UTC

Hi Raymond In the older (legacy) version of Essential Edit you can restrict the number of characters that can be typed in Line 1 to say less than 10000 by: private void editControl1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if (this.editControl1.GetCharCount(1)>9999) { MessageBox.Show("Char count exceeded"); e.Handled = true; } } Regards Arun


RG Raymond Gunawan February 3, 2005 05:15 PM UTC

The problem with that solution is that it doesn''t work when users are pasting into the formula editor. Is there a way to catch the paste event? Thanks >Hi Raymond > >In the older (legacy) version of Essential Edit you can restrict the number of characters that can be typed in Line 1 to say less than 10000 by: > >private void editControl1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) >{ > if (this.editControl1.GetCharCount(1)>9999) > { > MessageBox.Show("Char count exceeded"); > e.Handled = true; > } >} > >Regards >Arun >


AD Administrator Syncfusion Team February 4, 2005 06:05 PM UTC

Hi Raymond, 1) I tried adding copying and pasting a lot of text in the DotNetEdit sample that ships with Essential Edit. Here is a screenshot with nearly 200,000 characters in a single line. 2) Here is how you can take care of the paste issue: a) To catch Ctrl-V, so that it is not processed by the EditControl''s Context-Menu: private void Form1_Load(object sender, System.EventArgs e) { this.editControl1.Multiline = false; ContextMenu cm = this.editControl1.ContextMenu; foreach(MenuItem mi in cm.MenuItems) { this.RemoveShortcutInEditControl(mi); } } private void RemoveShortcutInEditControl(MenuItem miParent) { // Remove CtrlV shortcut. if(miParent.Shortcut == Shortcut.CtrlV) miParent.Shortcut = Shortcut.None; // Parse through the children recursively. foreach(MenuItem mi in miParent.MenuItems) { this.RemoveShortcutInEditControl(mi); } } b) To check the length of the text that is being pasted: private void editControl1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if((e.Control)&&e.KeyCode==Keys.V) { IDataObject data = Clipboard.GetDataObject(); if(data.GetDataPresent(DataFormats.Text)) { string text = (String)data.GetData(DataFormats.Text); if (text.Length>9999) { MessageBox.Show("Char count exceeded, cannot paste"); } else this.editControl1.Paste(); } } } Regards Arun


RG Raymond Gunawan February 4, 2005 06:31 PM UTC

Hi Arun, Thanks a lot for the code snippet! It seems to do what I wanted. Thanks again!

Loader.
Live Chat Icon For mobile
Up arrow icon