This section describes how Aspose.Editor user interface is organized and how application can customize and extend it.
Layout
Aspose.Editor desktop and client controls are control containers and host number of additional controls which comprise the user interface. These controls include:
- Main menu bar,
- One or more tool bars,
- Horizontal ruler control,
- Document view,
- Horizontal and vertical scroll bar controls,
- and status bar.
All controls except for the document view can be removed or replaced. Menu bar and tool bar controls can also be customized. Application can access controls using EditorControl.Bars collection.
Note. Editor control will dock hosted controls depending on which property was used to assign control. It doesn't distinguish control types.
Replacements
There are several properties in the Bars collection of type System.Windows.Form.Control. Each property can be assigned null to remove corresponding control(-s), or assigned standard or custom control for replacement. Static methods of class StandardControls can be used to create instances of standard controls, e.g. standard tool bars.
[C#]
// Remove main menu.
editorControl.Bars.Menu = null;
// Replace status bar with custom status bar.
editorControl.Bars.Status = new MyCustomStatusBar();
// Show two standard tool bars File and View.
editorControl.Bars.Tools = new Control[]
{
StandardControls.CreateToolBar(ToolBarType.File, editorControl),
StandardControls.CreateToolBar(ToolBarType.View, editorControl),
};
Customizing standard controls
Menu bar and tool bar can be customized. By this we understand adding and removing buttons and menu items. If you'd like to change appearance or behavior of the control, e.g. add sounds or irregular shapes, then you'll have to create custom control instead.
It is recommended to use commands (see. Using commands) to represent interface elements like menu items and tool bar buttons however it is not required. Suppose we have already created new custom command "OpenReport", here is how we can add it to the standard menu bar:
[C#]
// Get instance of the "OpenReport" command.
Command openReport = editorControl.Commands["OpenReport"];
// Get standard menu bar.
StandardMenuBar menu = editorControl.Bars.Menu as StandardMenuBar;
// If standard menu bar is set then append command to the 1st popup menu.
if ( menu != null )
menu.GetItemAt(0).MenuItems.Add(openReport.GetMenuItem());
Creating custom controls
Application can create custom control and then add it to the editor. The only requirement for a custom control is that it must inherit System.Windows.Forms.Control class. It is also recommended for a custom control to implement IAttachable interface. In the example custom control class is shown. It implements IAttachable interface in order to use Idle event from the editor control.
[C#]
/// <summary>
/// Sample custom control hosted by the editor.
/// </summary>
public class MemoryMeter: Label, IAttachable
{
/// <summary>
/// Initializes new instance of the custom control.
/// </summary>
public MemoryMeter()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint |
ControlStyles.DoubleBuffer, true);
AutoSize = true;
}
/// <summary>
/// Called when control is attached to the editor.
/// </summary>
public void OnAttached(object sender, AttachedEventArgs e)
{
mEditor = e.Editor;
// Subscribe to Idle event, we use it to update appearance.
mEditor.Idle += new EventHandler(mEditor_OnIdle);
}
/// <summary>
/// Called when control is detached from the editor.
/// </summary>
public void OnDetached(object sender, EventArgs e)
{
if ( mEditor != null )
{
// Unsubscribe from the Idle event.
mEditor.Idle -= new EventHandler(mEditor_OnIdle);
mEditor = null;
}
}
/// <summary>
/// When editor enters Idle this method updates control appearance.
/// </summary>
private void mEditor_OnIdle(object sender, EventArgs e)
{
// Get garbage collector memory usage.
Text = GC.GetTotalMemory(false).ToString();
}
private EditorControl mEditor;
}
In the application code we can add this control to the EditorBars.Tools as follows:
[C#]
editorControl.Bars.Tools = new Control[]{
StandardControls.CreateToolBar(ToolBarType.File, editorControl),
StandardControls.CreateToolBar(ToolBarType.View, editorControl),
new MemoryMeter(), };