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

Extending or Overriding an existing ToolBar Item

You're able to override the existing RichTextBox toolbar menu selects and buttons or create new ones. The example below overrides and extends (still sets the Font as the current Select does) the existing Font select. Just add your own additional logic and you can do most that you'll require. The Documentation (Start/Programs/RichTextBox v2.0/Documentation) covers these classes and all their members.

 

In your .aspx.cs or server script -

 

protected RichTextBoxControl.ToolbarButton toolButton;

protected RichTextBoxControl.ToolbarMenu fontMenu;

 

private void Page_Load(object sender, System.EventArgs e)

 {

     fontMenu = new RichTextBoxControl.ToolbarMenu("FontMenu", true);

     RichTextBoxControl.ToolbarMenuItem item = new  

     RichTextBoxControl.ToolbarMenuItem();

     item.Name = "Tahoma"; 

     item.Value = "Tahoma";

     fontMenu.Items.Add(item);

     item = new RichTextBoxControl.ToolbarMenuItem();

     item.Name = "Arial"; 

     item.Value = "Arial";

     fontMenu.Items.Add(item);

 

     fontMenu.OnChange = "myMenuHandler";

     fontMenu.Title = "Font";

     this.RichTextBox1.CreateToolbarMenu(fontMenu);

 }

 

In your client script of your .aspx page -

 

<script language="javascript" type="text/javascript">

  function myMenuHandler(editor,isHtmlMode,text,value)

  {

      //the following 3 lines are from the existing function

      if (isHtmlMode) return;

      editor.focus();

      editor.document.execCommand('fontname','',value);

      

      //add you additional logic here to extend the code fired above

   

   }

</script>

 

Or with an existing toolbar button -

 

 protected RichTextBoxControl.ToolbarButton toolButton;

 

 toolButton = new RichTextBoxControl.ToolbarButton("Print", true);

 toolButton.ClientOnClickFunction = "myButtonHandler";

 this.RichTextBox1.CreateToolbarButton(toolButton);

 

In your client script of your .aspx page -

 

<script language="javascript" type="text/javascript">

  function myButtonHandler(editor, isHtmlMode)

  {

       alert('print');

  }

</script>

 

To create a new toolbar button the code would be like the following -

 

toolButton = new RichTextBoxControl.ToolbarButton("NewButton", false); 

 

You'd then add new .gif files to the appropriate images directory called NewButton.gif and NewButton_over.gif so that these are picked up in the render of the new image button.




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