Link to home
Start Free TrialLog in
Avatar of hqdev
hqdevFlag 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

Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

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

Avatar of 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
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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