RichTextBox fixed width
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngrichtextbox' list.


Anand Rajagopal - CTD, Chennai.
Hi,
I want to maintain a fixed length for the richtextbox control. I mean, i
want to restrict user to allow only 50 characters per line. If he tries to
enter more than fifty characters, the control/cursor should move to the next
line of the RTB. Currently if the word being entered is bigger than the
screen size, then a horizontal scroll bar appears and the text is shown on
the same line.
Please let me know how i can restrict the user to enter only 50 characters
per line. I am ready to use true type font for the data entry.

Thanks & Regards,
Anand R

Reply to this message...
 
    
Ollie Cornes

Hi Anand,

Apologies for being a little slow replying, I wanted to spend some time
testing this code out to make sure it is solid. Add this to the page
containing the RichTextBox:

<script language="javascript" >
function checklength()
{
if (richtext1_x5.document.body.innerText.length>=10)
{
document.getElementById('textBox').focus();
}
}
richtext1_x5.document.onkeypress = checklength;
</script>

This script is for a RichTextBox called "richtext1". It adds "_x5" onto
the end of the editor ID to access the iframe that contains the document
(note this may change in a future release). It then applies an
onkeypress event handler. The handler then checks the length of the
innerText property and if it's over 10 it moves the focus to an HTML tag
called textBox. To use this in your code replace "richtext1" with the
name of your RichTextBox, and change "textBox" to the ID of the control
you want focus to move to when the RichTextBox hits the character limit.

Does that give you what you need?

Ollie
--
http://www.richtextbox.com/
The no. 1 content editor for ASP.NET

[Original message clipped]

Reply to this message...
 
    
Anand Rajagopal - CTD, Chennai.
Hi Ollie,
Thanks for the reply.
But actually instead of moving the focus to the next control(textbox), i
rather want to move the focus/cursor to the next line in the same
Richtextbox.
Can i force a carriage return there?

Regards,
Anand Rajagopal

-----Original Message-----
From: Ollie Cornes [mailto:Click here to reveal e-mail address]
Sent: Wednesday, July 31, 2002 8:09 PM
To: aspngrichtextbox
Subject: [aspngrichtextbox] RE: RichTextBox fixed width

Hi Anand,

Apologies for being a little slow replying, I wanted to spend some time
testing this code out to make sure it is solid. Add this to the page
containing the RichTextBox:

<script language="javascript" >
function checklength()
{
if (richtext1_x5.document.body.innerText.length>=10)
{
document.getElementById('textBox').focus();
}
}
richtext1_x5.document.onkeypress = checklength;
</script>

This script is for a RichTextBox called "richtext1". It adds "_x5" onto
the end of the editor ID to access the iframe that contains the document
(note this may change in a future release). It then applies an
onkeypress event handler. The handler then checks the length of the
innerText property and if it's over 10 it moves the focus to an HTML tag
called textBox. To use this in your code replace "richtext1" with the
name of your RichTextBox, and change "textBox" to the ID of the control
you want focus to move to when the RichTextBox hits the character limit.

Does that give you what you need?

Ollie
--
http://www.richtextbox.com/
The no. 1 content editor for ASP.NET

[Original message clipped]

| [aspngrichtextbox] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspngrichtextbox.asp = JOIN/QUIT

Reply to this message...
 
    
Ollie Cornes

Hi Anand,

I'm sorry, I entirely misunderstood what you are trying to do.

The requirement you have there would require some rather more involved
client script. This is because the document is HTML, not a text file so
determining when you reach the end of a line is fairly non-trivial. I
expect that you would need to create a list of HTML tags that constitute
the end of a line and check the character count until the next tag. I
would expect that valid end-of-line tags would include /BR, /P, /H1,
/H2, /H3, HR, etc.

Do you mind if I ask why you have this requirement?

Ollie
--
http://www.richtextbox.com/
The no. 1 content editor for ASP.NET

[Original message clipped]

Reply to this message...
 
 
System.Windows.Forms.RichTextBox




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com