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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Limit max number of characters in a line

Thread ID:

Created:

Updated:

Platform:

Replies:

24409 Feb 3,2005 02:29 PM UTC Feb 4,2005 06:31 PM UTC Windows Forms 4
loading
Tags: EditControl
Raymond Gunawan
Asked On February 3, 2005 02:29 PM UTC

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.

Administrator [Syncfusion]
Replied On 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

Raymond Gunawan
Replied On 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 >

Administrator [Syncfusion]
Replied On 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

Raymond Gunawan
Replied On 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!

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;