|
Using your own Context Menu
The default context menu contains the buttons for Cut, Copy, Paste, Delete, Select
All for all around the editor. Also it shows up Table Properties Editor, Table Cell
Properties Editor and Hyperlink Editor if the Active Html Element is a table, table's
cell or hyperlink respectively.
If you like to replace this default context menu and want to use your own context
menu, you can easily do that by following steps:
- Create your own ContextMenuStrip and name it as "contextMenuStrip1"
- Set the EditorContextMenuStrip to this ContextMenuStrip

Whenever you add your own Context Menu Strip, the default context menu wont be
shown. You wont have to take any effort to hide the default context menu in this
case. But if you dont use your own context menu and if you dont want to show the
default context menu either, then, you can set the property ShowDefaultContextMenu
to false.
Now, if you want to get all the default command buttons in your new customized Context
menu, then you may use the following table of reference which shows what are the
public methods associated with each commands in the default ContextMenu.
|
|
Context Menu Item |
Associated public Methods
Usage: htmlEditor1.Operations.MethodName() |
|
|
|
|
 |
Cut
|
public void Cut() |
 |
Copy |
public void Copy() |
 |
Paste |
public void Paste() |
|
|
Delete |
public void Delete() |
|
|
Select All |
public
void SelectAll() |
 |
Table Properties |
public void ShowTableDialog() |
|
|
Cell Properties |
public void ShowTableCellEditor() |
 |
Link Properties |
public void ShowHyperLinkDialog() |
 |
Image |
public void ShowImageDialog() |
In addition to the above reference, you may want to set visibility of certain buttons
based on the selection status of the editor. For example, if the ActiveHtmlElement
is not a Table Element then you may not need to keep "Table
Properties" item visible in your Context
Menu. In order to program the visibility of a button in Context Menu, you can take
help of the SelectionState property of the editor.
For example, the following snippet will check if the active element is
Table or Table Cell so that the appropriate button is set visible.

Additionally, you may want to Disable or Enable the Cut, Copy, Paste, Delete menu
items based on the selection in the editor's content. For example, if there is no text selected
in the editor, it is more practical to disable the Cut, Copy, Delete menu item. The SelectionState property
will help you to do that. The following list shows the usage of some of the sub
properties of SelectionState property.
- htmlEditor1.SelectionState.CanCut
- htmlEditor1.SelectionState.CanCopy
- htmlEditor1.SelectionState.CanDelete
- htmlEditor1.SelectionState.CanPaste
- htmlEditor1.SelectionState.CanRedo
- htmlEditor1.SelectionState.CanUndo
Moreover if you want to handle the commands by yourself and build your own mechanism instead of
using the
built-in properties you have
the following public method available under the SelectionState property.
public bool QueryCommandEnabled(string
commandName)
This method Returns a Boolean value that indicates whether a specified command can
be successfully executed using execCommand, given the current state of the document.
So, in order to decide if copy, paste etc, menu items should be enabled
or disabled, you can use the following snippet:
Although, you dont need to add these lines of code in your program as the
factory toolstrip items are already sensible to these states.
|