override existing buttons and functions

Add-in Express™ Support Service
That's what is more important than anything else

override existing buttons and functions
 
Subscribe
Michael Müller




Posts: 46
Joined: 2014-07-17
Hi,

I use the current version from "Add-in Express for Office and .NET, Standard" and use Word 2003.
I want to hide or override following buttons (bold, italic, underline) in the commandBar formatting in word 2003.

I have created a new commandbar with the CommandBarName="Formatting".
In this I created three buttons, with the id 113(bold), 114(italic) and 115(underline).

Now I want have following behaviour:
* standard word buttons bold, italic and underline: visible = false
* our new buttons bold, italic and underline: visible = true
* behaviour of the button bold: text also get bold but with special format, style...

Also I want to override following functions: FileSave, FileSaveAs, InsertAutoText and ViewDocumentMap.

How can I realize this with AddinExpress?

Regards

Rosemarie Haberecht
Posted 04 Jun, 2019 08:51:22 Top
Andrei Smolin


Add-in Express team


Posts: 16306
Joined: 2006-05-11
Hello Rosemarie,

I've put the following controls onto the add-in module of my test add-in:
#region Component Designer generated code
/// <summary>
/// Required by designer support - do not modify
/// the following method
/// </summary>
private void InitializeComponent()
{
    this.components = new System.ComponentModel.Container();
    this.adxBuiltInControl1 = new AddinExpress.MSO.ADXBuiltInControl(this.components);
    this.adxCommandBar1 = new AddinExpress.MSO.ADXCommandBar(this.components);
    this.CustomBoldButton = new AddinExpress.MSO.ADXCommandBarButton(this.components);
    // 
    // adxBuiltInControl1
    // 
    this.adxBuiltInControl1.CommandBar = this.adxCommandBar1;
    this.adxBuiltInControl1.ControlTag = "d1f5d554-c5d6-47ca-a1b2-9e9248c2f673";
    this.adxBuiltInControl1.Id = 113;
    this.adxBuiltInControl1.ActionEx += new AddinExpress.MSO.ADXActionEx_EventHandler(this.adxBuiltInControl1_ActionEx);
    // 
    // adxCommandBar1
    // 
    this.adxCommandBar1.CommandBarName = "Formatting";
    this.adxCommandBar1.CommandBarTag = "5999fee5-6234-4d50-9cac-93ecdf75dd47";
    this.adxCommandBar1.Controls.Add(this.CustomBoldButton);
    this.adxCommandBar1.UpdateCounter = 3;
    // 
    // CustomBoldButton
    // 
    this.CustomBoldButton.BeginGroup = true;
    this.CustomBoldButton.Caption = "MyBold";
    this.CustomBoldButton.ControlTag = "d1f5d554-c5d6-47ca-a1b2-9e9248c2f673";
    this.CustomBoldButton.Id = 113;
    this.CustomBoldButton.ImageTransparentColor = System.Drawing.Color.Transparent;
    this.CustomBoldButton.UpdateCounter = 6;
    // 
    // AddinModule
    // 
    this.AddinName = "MyAddin1";
    this.SupportedApps = AddinExpress.MSO.ADXOfficeHostApp.ohaWord;

}
#endregion

private AddinExpress.MSO.ADXBuiltInControl adxBuiltInControl1;
private AddinExpress.MSO.ADXCommandBar adxCommandBar1;
private AddinExpress.MSO.ADXCommandBarButton CustomBoldButton;


I handle the ADXBuiltInControl.ActionEx event as follows:

private void adxBuiltInControl1_ActionEx(object sender, ADXCancelEventArgs e)
{
    Office.CommandBarButton btn = (e.Control as Office.CommandBarButton);
    if (btn != null)
    {
        if (btn.Tag == this.CustomBoldButton.ControlTag)
        {
            //MessageBox.Show("this is my button");
            e.Cancel = true;
            Word.Selection sel = WordApp.Selection;
            // TODO: check what sel contains if no document is open
            Word.Range range = sel.Range;
            range.Italic = 1;
            range.Bold = 1;
            Marshal.ReleaseComObject(range); range = null;
            Marshal.ReleaseComObject(sel); sel = null;
        }
        else
        {
            MessageBox.Show("this is the built-in button");
        }
    }
}


Michael Müller writes:
Also I want to override following functions: FileSave, FileSaveAs, InsertAutoText and ViewDocumentMap.


You need to find out the IDs of these controls and use the technique above to handle them.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 05 Jun, 2019 07:49:30 Top
Michael Müller




Posts: 46
Joined: 2014-07-17
Hi Andrei,

thanks this work how we want for the buttons.

But we also want to override the method "InsertAutoText" from word.

How can I do this?

Regards

Rosemarie Haberecht
Posted 06 Jun, 2019 03:54:12 Top
Andrei Smolin


Add-in Express team


Posts: 16306
Joined: 2006-05-11
Hello Rosemarie,

You can hide the popup listing AutoText entries in the main menu and on the corresponding commandbar and create a custom popup listing all autotext entries.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 06 Jun, 2019 04:18:41 Top
Michael Müller




Posts: 46
Joined: 2014-07-17
Hi Andrei,

what do you mean with popup listing?

Also I have a other Problem. The builtin for bold works fine, but when the user use STRG+Shift+F our override for bold do not work. How can i resolve this? Must I create a new Keyboardshortcut, which triggers our bold method?

Regard

Rosemarie Haberecht
Posted 07 Jun, 2019 07:03:47 Top
Michael Müller




Posts: 46
Joined: 2014-07-17
Hallo Andrei,

Can I override the word function bold, and when how?

Regards

Rosemarie Haberecht
Posted 07 Jun, 2019 07:11:49 Top
Andrei Smolin


Add-in Express team


Posts: 16306
Joined: 2006-05-11
Hello Rosemarie,

Michael Müller writes:
what do you mean with popup listing?


Insert | Autotext expands 1) the Insert Popup, 2) the Autotext popup. the latter contains 1) button Autotext (it opens the AutoText tab of the AutoCorrect dialog), 2) button New..., 3) the whole bunch of popups; each of the popus contains part of the Autotext entries available on the AutoText tab of the AutoCorrect dialog.

I suggest that you use a different approach:

Create a custom button (ADXCommandBarButton) that performs these actions. Sets its Id property to 1; thus you won't need to use the Builtin Control Connector. Set its ShortcutText to Ctrl+B or Ctrl+Shift+B; no ADXKeyboardShortcut is required for this. In the Click event handler, perform your changes:


            Word.Selection sel = WordApp.Selection;
            // TODO: check what sel contains if no document is open
            Word.Range range = sel.Range;
            range.Italic = 1;
            range.Bold = -1;
            range.Underline = Word.WdUnderline.wdUnderlineDash;
            Marshal.ReleaseComObject(range); range = null;
            Marshal.ReleaseComObject(sel); sel = null;


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 07 Jun, 2019 08:49:59 Top
Michael Müller




Posts: 46
Joined: 2014-07-17
Hi Andrei,

my solution for bold is now a button with "strg+Shift+f" and a builtin with id=113.
So it works how we want.

Thanks and Regards

Rosemarie Haberecht
Posted 12 Jun, 2019 05:19:16 Top
Andrei Smolin


Add-in Express team


Posts: 16306
Joined: 2006-05-11
Welcome!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 12 Jun, 2019 06:24:58 Top