Avatar of hqdev
hqdev
Flag for Canada asked on

Visio Viewer 2007 in a VB.NET WinForm application

HI experts,

Is there a way to use Visio Viewer 2007 in a WinForm application without havinf Visio 2007 installed on the machine?
I've tried an example on MSDN (http://msdn.microsoft.com/en-us/library/dd392798.aspx) but I'm gettinh the message "WindowLess ActiveX control not supported".
I'm following the exact instructions in the article, but it's not working.
I'm using VS 2008 on Vista.

Anyone having a working example of Visio viewer in a Winform? (Without Visio on the machine, of course)
I'm programming in VB but I've tried the example in C# to be sure I was doing the right thing.

Thanks
public partial class Form1 : Form
    {
        private AxVisioViewer.AxViewer viewer;
 
        /// <summary>
        /// The Visio Viewer OM
        /// </summary>
        public AxVisioViewer.AxViewer Viewer
        {
            get
            {
                return this.viewer;
            }
        }
 
        public Form1()
        {
            this.InitializeComponent();
            this.Resize += new EventHandler(this.UpdateSize);
            this.viewer = new AxVisioViewer.AxViewer();
            this.Controls.Add(this.viewer);
            this.viewer.CreateControl();
 
            this.viewer.Location = new Point(0, 0);
            this.UpdateSize(null, null);
         
        }
 
        public void UpdateSize(object obj, EventArgs ea)
        {
            this.viewer.ClientSize = new Size(this.ClientSize.Width - 150, this.ClientSize.Height - 150);
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            this.viewer.Load("C:\\users\\username\\documents\\viewer\\test.vsd");
 
        }        
 
    }

Open in new window

Visual Basic.NET

Avatar of undefined
Last Comment
hqdev

8/22/2022 - Mon
Todd Gerbert

This works for me...
Imports AxVisioViewer
Public Class Form1
	Private TheViewer As AxViewer
	Public Sub New()
 
		InitializeComponent()
 
 
		TheViewer = New AxViewer()
		TheViewer.Dock = DockStyle.Fill
		Me.Controls.Add(TheViewer)
		TheViewer.CreateControl()
 
		TheViewer.Location = New Point(0, 0)
	End Sub
 
	Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		Dim ofd As New OpenFileDialog()
 
		ofd.CheckFileExists = True
		ofd.CheckPathExists = True
		ofd.DefaultExt = ".vsd"
		ofd.Multiselect = False
 
		If (ofd.ShowDialog() = Windows.Forms.DialogResult.OK) Then
			TheViewer.Load(ofd.FileName)
			TheViewer.Refresh()
		End If
 
		ofd.Dispose()
	End Sub
 
	Private Sub LoadVisioDrawing()
		Dim ofd As New OpenFileDialog()
 
		ofd.CheckFileExists = True
		ofd.CheckPathExists = True
		ofd.DefaultExt = ".vsd"
		ofd.Multiselect = False
 
		If (ofd.ShowDialog() = Windows.Forms.DialogResult.OK) Then
			TheViewer.Load(ofd.FileName)
			TheViewer.Refresh()
		End If
 
		ofd.Dispose()
	End Sub
End Class

Open in new window

hqdev

ASKER
Thanks for your reply but I'm getting the same error message with your code:

Unable to get the window handle for the 'AxViewer' control. Windowless ActiveX controls are not supported.

What version of Visual Studio and on what OS are you?
ASKER CERTIFIED SOLUTION
Todd Gerbert

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
hqdev

ASKER
How silly of me, I had the old 2005 version of the viewer installed, but I was using the 2007 DLLs!
So I've installed the 2007 viewer and it's working now.

Thanks
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck