View Single Post
 
Old 11-20-2018, 08:57 AM
ArtKilp ArtKilp is offline Windows 8 Office 2016
Novice
 
Join Date: Jan 2016
Posts: 18
ArtKilp is on a distinguished road
Default Word 2017 + VSTO 2015 events

Hi,

How do I set up events for Word / C#? That is, something like "display message on double click" is good enough, but I need it to work on any document when this addin is active (not disabled etc.).

I use pretty much everywhere else Interop, but if Tools is required, then Tools is ok too.

I have a start here:
Code:
namespace WordAddIn1
{
    public partial class ThisAddIn
    {
        public event Microsoft.Office.Tools.Word.ClickEventHandler BeforeDoubleClick;

        private void DocumentBeforeDoubleClick()
        {
            Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
            vstoDoc.BeforeDoubleClick += new Microsoft.Office.Tools.Word.ClickEventHandler(ThisDocument_BeforeDoubleClick);
        }

        void ThisDocument_BeforeDoubleClick(object sender, Microsoft.Office.Tools.Word.ClickEventArgs e)
        {
            Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
            System.Windows.Forms.MessageBox.Show(vstoDoc.Name + " was double-clicked.");
        }
//and below is then private void ThisAddIn_Startup etc.
This mixes now things up (document-addin and tools-interop) and that's why it isn't working. But how to fix it?
Reply With Quote