Reputation: 2828
Using the below code I toggle the shapes visibility in the word document. The shapes are still visible when the wrap format is set to wdWrapInline. To clarify the Visible property is correctly set to false but the shape is still visible in the document. With any other wrap format the shape visibility is toggled properly. Any idea why it doesnt work with wdWrapInline?
Word.Application wordApplication = Globals.ThisAddIn.Application;
Word.Document document = wordApplication.ActiveDocument;
Word.Shapes shapes = document.Shapes;
foreach (Word.Shape shape in shapes)
{
// If shape.WrapFormat.Type = Word.WdWrapType.wdWrapInline
// Then the Visible is set to false but it is still visible in the document
shape.Visible == MsoTriState.msoFalse? MsoTriState.msoTrue : MsoTriState.msoFalse
}
Upvotes: 0
Views: 281
Reputation: 25693
It doesn't work with Inline because Inline doesn't have that property. It sounds a bit insane, but...
Until recently it wasn't possible to apply inline formatting to a Shape object. You had InlineShapes and Shapes, and InlineShapes have no Visible property because Word handles them like text. This still applies to a Shape with the wrap format "Inline".
You have to apply the "Hidden" font formatting to a graphic that's formatted "inline".
foreach (Word.Shape shape in shapes)
{
// If shape.WrapFormat.Type = Word.WdWrapType.wdWrapInline
// Then the Visible is set to false but it is still visible in the document
//You have to format it as a text character:
if (shape.WrapFormat.Type == Word.WdWrapType.wdWrapInline)
{
shape.Anchor.Font.Hidden = true;
}
else
{
shape.Visible == MsoTriState.msoFalse? MsoTriState.msoTrue : MsoTriState.msoFalse
}
}
Upvotes: 1