Set focus to Visio document programatically?

  • Thread starter Mats-Lennart Hansson
  • Start date
M

Mats-Lennart Hansson

Hi,
Is there a way to set focus on a Visio document programatically? From a
windows form (c#) I can set the active page, but I also want the Visio
document to get focused. Can this be done?

Thanks,
Mats-Lennart
 
C

Chris Roth [ Visio MVP ]

I think this is a problem of "activating" an application. It sounds to me
like you are driving Visio from an .exe???

Check out this link if I'm on the right track in the first paragraph. I
don't know if this is the best way, but at least it's an option:

http://www.dotnet247.com/247reference/msgs/58/292191.aspx

--

Hope this helps,

Chris Roth
Visio MVP
 
M

Mats-Lennart Hansson

Thanks for a quick reply, but I was hoping for something simpler.

What I have is a Visio Add-in, where I have a number of toolbar buttons.
When I click a button, a window form is created and shown to the user. This
form contains some information about the Visio document and the user is able
to double-click on information to activate the desired page. This works fine
by using

vsoPage.Application.ActiveWindow.Page = pageName;

However, I also want to minimize my form and then put the Visio document "on
top" of the screen. Since this is an add-in, I have access to the Document
object as well as the Page object. Is there a way to use these perhaps?

Thanks,
Mats-Lennart
 
C

Chris Roth [ Visio MVP ]

I don't fully understand. You are able to put the document/page that you
want into the active Visio window. What is missing?

Do you want some sort of Visio-Full-Screen mode? Visio has this (press F5)
and in code you can do this:

visio.Application.DoCmd(visCmdFullScreenMode )

Not sure if that is what you need, though.

--

Hope this helps,

Chris Roth
Visio MVP
 
M

Mats-Lennart Hansson

Ok, maybe I'm a bit unclear. I'll try to explain it again:

In Visio, I have a toolbar button that opens up a non-modal window form in
front of Visio. This form contains references to the Visio document (pages
and shapes). When I click on each reference I want the Visio document to set
the active page and zoom into the actual shape (this works). But I also want
to focus the Visio window. Since the form is non-modal the user can, and
will, use other applications during runtime so I can't assume that just
hiding the form will bring focus to the Visio window. In other words, is
there a way to set focus on a Visio window using any of the standard objects
Document, Application or Page?

Thanks,
Mats-Lennart
 
M

Markus Breugst

I don't think that this is possible by Visio itself. We have implemented the
following method "ToFront". Hope this is what you are looking for.

Best regards,
Markus


using System.Runtime.InteropServices;

[DllImport("User32",EntryPoint="SetForegroundWindow")]
private static extern bool SetForegroundWindow(IntPtr hWnd);

public void ToFront()
{
IntPtr _handle;

_handle = (IntPtr) visioApplication.WindowHandle;
SetForegroundWindow( _handle );
}
 
M

Mats-Lennart Hansson

Ok, I was hoping for a built-in function in Visio but this works perfect.
Thanks! (And thanks to Chris as well).

/Mats-Lennart

Markus Breugst said:
I don't think that this is possible by Visio itself. We have implemented the
following method "ToFront". Hope this is what you are looking for.

Best regards,
Markus


using System.Runtime.InteropServices;

[DllImport("User32",EntryPoint="SetForegroundWindow")]
private static extern bool SetForegroundWindow(IntPtr hWnd);

public void ToFront()
{
IntPtr _handle;

_handle = (IntPtr) visioApplication.WindowHandle;
SetForegroundWindow( _handle );
}



Mats-Lennart Hansson said:
Ok, maybe I'm a bit unclear. I'll try to explain it again:

In Visio, I have a toolbar button that opens up a non-modal window form in
front of Visio. This form contains references to the Visio document (pages
and shapes). When I click on each reference I want the Visio document to set
the active page and zoom into the actual shape (this works). But I also want
to focus the Visio window. Since the form is non-modal the user can, and
will, use other applications during runtime so I can't assume that just
hiding the form will bring focus to the Visio window. In other words, is
there a way to set focus on a Visio window using any of the standard objects
Document, Application or Page?

Thanks,
Mats-Lennart

to
paragraph.
 

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