Knowledge Base > RichTextBox > Features Knowledge Base Home | Login
Search the Knowledge Base
 
Start Search in the Following Category

Align selected line of text only

When you click the left/right/center justify buttons it calls the execCommand method for the selected element and so moves all of the text (rather than just the selected line of text) as it's usually all in the same P element.

 

If you're using RichTextBox1.ReturnKeyBehavior = BreakMode.LineBreak; then you could implement the following so that it will only move the selected line of text.

 

Add an input button or new toolbar button with the following event and function call (to do a center justify) -

 

onclick="setAlignment('center')

 

The javascript function in your .aspx page -

 

<script type=text/javascript language=javascript>

function setAlignment(align)

                 { 

                    var selectedText = RichTextBox1_x5.document.selection;

                    var newRange = selectedText.createRange();

                    var x = RichTextBox1_x5.document.body.innerHTML;

                    var newHtml = x.replace(new RegExp([newRange.text + '<BR>']),'<div align=' + align + '>' + newRange.text + '</div>');

                    RichTextBox1_x5.document.body.innerHTML = newHtml;

                 }

</script>

 

You should then find this is aligns on a selected line basis rather than all the lines when ReturnKeyBehavior = BreakMode.LineBreak; so that <BR> tags are inserted.

 

In this case the RichTextBox instance ID = RichTextBox1 so you’ll need to modify this (be sure to add the _x5 suffix which refers to the Editor/Iframe) if your ID is different.




Did this page answer your question? If not, try the Forums or contact us.

Copyright Richer Components 2005. All rights reserved. No part of this article may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording or otherwise) without the prior written permission of Richer Components. All brand names and product names used in this article are trade names, service marks, trademarks, or registered trademarks of their respective owners.


Knowledge Base Software - myKB.com