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.

Limit max number of characters in a line

Thread ID:

Created:

Updated:

Platform:

Replies:

24409 Feb 3,2005 09:29 AM Feb 4,2005 01:31 PM Windows Forms 4
loading
Tags: EditControl
Raymond Gunawan
Asked On February 3, 2005 09:29 AM

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 10:18 AM

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 12:15 PM

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 01:05 PM

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 01:31 PM

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.

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.

;