Problems initializing multiple Visio ActiveX controls...

G

gil.assayag

Hi!

I'm developing a C# .NET 1.1 application. Basically it's a form that
holds two Visio Drawings, both inherit from a base wrapper class I
named VisioDrawingBase (that has an axDrawingControl1 member). Problem
is that a stencil that opens in the initialization opens twice in one
of the controls (instead of one in each of the controls).

In this base class, I register to the event 'VisibleChanged', as I saw
in one of the samples, in order to initialize:

private void axDrawingControl1_VisibleChanged(object sender,
System.EventArgs e)
{
// Only initialize the first time.
if (this.axDrawingControl1.Visible && m_bFirstTime)
{
this.axDrawingControl1.Focus();
Initialize();
}
}

The initialization is (also in the base class):
protected void Initialize()
{
Visio.Documents VisDocs =
axDrawingControl1.Window.Windows.Application.Documents;

// Open the sites stencil
string sStencilPath = Application.StartupPath + "\\..\\" +
Constants.sVisResFolder + Constants.sVisStencilSites;

VisDocs.OpenEx(sStencilPath, (short)
Visio.VisOpenSaveArgs.visOpenRO);
}

However, this stencil opens twice in one of the controls.

Any idea what I'm doing wrong? Any ideas for a workaround? Am I
initializing in the right place?

Thank you very much,
Gil
 
H

H Wu

You're in luck ... I just figured it out today.
Basically you have to use User32.dll API SetFocus method.

Here what to do, you must put this before the class:
using System.Runtime.InteropServices;
Put this in a class:
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SetFocus(IntPtr hWnd);

//In your form just call SetFocus by pass Visio ActiveX control window handle
m_ovWindow = axDrawingControl1.Window;
SetFocus(axDrawingControl1.Handle);
m_ovWindow.Document.Application.Documents.OpenEx(@"...\Process.vss",
(short)Visio.VisOpenSaveArgs.visAddDocked);
 
G

gil.assayag

You're a king!

Works like a charm... Thank you so much. I spent so many hours trying
to find a work around...

Where did you figure this out from? Maybe I wasn't looking in the right
places?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top