Configure a Visio drawing window from a C# add-in
Visio's Window object controls the drawing surface's presentation. Set its properties after a drawing window exists, rather than assuming the application always has an active document.
This example targets an existing VSTO/Visio desktop integration on Windows. It is not an ASP.NET server automation technique or a replacement for installing Visio.
Configure the active drawing
Requires Visio desktop, a compatible Visual Studio Office-development setup, and a Visio VSTO add-in with the generated interop references. Add this method to ThisAddIn and call it from an existing Ribbon button after opening a drawing:
private void ConfigureDrawingWindow() {
Microsoft.Office.Interop.Visio.Window window = this.Application.ActiveWindow;
if (window == null || window.Type != (short)Microsoft.Office.Interop.Visio.VisWinTypes.visDrawing)
return;
window.ShowRulers = 0;
window.ShowGrid = 0;
window.ShowScrollBars = 0;
window.ShowPageTabs = false;
window.Zoom = 1.0;
}
The active drawing hides rulers, grid, scrollbars and page tabs, with zoom set to 100%. These are window-display settings. They do not turn the application's top-level window into an operating-system full-screen window.
Preserve the surrounding host
For an existing embedded Visio Drawing Control, obtain its actual Window and apply the same window properties after control/document initialization. Keep the host's current ActiveX wrapper and architecture-compatible references. Do not blindly select an old Visio 12.0 toolbox entry on a newer installation.
If this is a temporary presentation mode, record each previous setting and restore it when leaving that mode. ShowScrollBars is a flags-style integer rather than a Boolean, ShowPageTabs is Boolean, and Zoom is a magnification factor. Use -1 for fit-to-window when that is the intended view instead of assuming 1.0 fits the page.
Official references



Author: Herman Schoenfeld