JoeGeeky
JoeGeeky

Reputation: 3796

Drawing on VSTO WordDocument without saving shapes in the document

We are trying to create a VSTO Word 2013 Document Addin which overlays visual indicators on the document while the user is editing to make them aware of problems with the information they are typing. It seems this can be done by drawing shapes such as the sample below. In our case, we don't want these shapes saved with the document, we just want them available when editing the document with the addin installed. Can anyone explain how we can do this?

private void DrawIt()
{
    object oRng = Globals.ThisDocument.Application.Selection.Range;
    var doc = Globals.ThisDocument.InnerObject;

    var shape = doc.Shapes.AddLine(100f, 100f, 100f, 200f, ref oRng);

    if (shape == null) return;

    shape.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
    shape.Line.DashStyle = Microsoft.Office.Core.MsoLineDashStyle.msoLineDash;
    shape.Line.Weight = 3;
}

Upvotes: 1

Views: 397

Answers (1)

Michael Gunter
Michael Gunter

Reputation: 12811

I'm 95% certain that there's nothing in the Word object model that's going to allow you to do what you're after. Shapes, as you've discovered, are considered a part of the document. There is no built-in mechanism for displaying arbitrary shapes in any other way. You can manually do this by managing your own windows -- get the Hwnd of the window that contains your document, then use Win32 (and/or WinForms/WPF) to create the the UI that you want to display.

Upvotes: 2

Related Questions