Using your own control instead of Toolbars

In the previous chapter, we have shown you how you can use your own toolbar control to host some of the toolbar buttons selectively. Sometimes, you might think about calling the same methods (that are executed when a toolbar button is clicked) from your own control. For example, if you have a button in your Windows Form where you want that, if that button is clicked, the Image Insert Dialog should be shown as if the user pressed the image toolbar button. Yes, you can call any toolbar button's logic just from your own control.

Here is the snippet about how to call the Image Dialog logic from your own button control (say your button name is button1).

private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
{
    wpfHtmlEditor1.ToolbarItemOverrider.OnImageButtonClicked(sender, e);
}

Yes, all other Toolbar button click methods can be found in the ToolbarItemOverrider collection.

Here is a screenshot of the Intellisense for this collection.

ToolbarItemOverrider Intellisense

So, lets design a form with 3 buttons, Bold, Italic and Underline as shown in the following screenshot:

Own control instead of toolbars

Lets their name be btnBold, btnItalic and btnUnderline and their click event handlers can be written as

C#

private void BntBold_Click(object sender, RoutedEventArgs e)
{
    wpfHtmlEditor1.ToolbarItemOverrider.OnBoldButtonClicked(sender, e);
}

private void BntItalic_Click(object sender, RoutedEventArgs e)
{
    wpfHtmlEditor1.ToolbarItemOverrider.OnBoldButtonClicked(sender, e);
}

private void BntUnderline_Click(object sender, RoutedEventArgs e)
{
    wpfHtmlEditor1.ToolbarItemOverrider.OnBoldButtonClicked(sender, e);
}

VB

Private Sub BntBold_Click(sender As Object, e As RoutedEventArgs) Handles BtnBold.Click
 wpfHtmlEditor1.ToolbarItemOverrider.OnBoldButtonClicked(sender, e)
End Sub

Private Sub BntItalic_Click(sender As Object, e As RoutedEventArgs) Handles BtnItalic.Click
 wpfHtmlEditor1.ToolbarItemOverrider.OnBoldButtonClicked(sender, e)
End Sub

Private Sub BntUnderline_Click(sender As Object, e As RoutedEventArgs) Handles BtnUnderline.Click
 wpfHtmlEditor1.ToolbarItemOverrider.OnBoldButtonClicked(sender, e)
End Sub
Last updated on May 28, 2015