Selecting newly drawn shapes

L

Larry F.

I've got a Visio 2003 ActiveX control in a Visual Studio 2003 .Net
form. The trouble I'm having is that I can't seem to select shapes
that I have just drawn.

Here's my C# code:

using Visio = Microsoft.Office.Interop.Visio;
....
Visio.Page Page = /* initialized to a valid page */
Visio.Shape shape;
for (int i = 1; i <= 5; i++) {
shape = Page.DrawRectangle(i, 2, i+1, 3);
shape.Text = i.ToString();
shape.Name = "Number " + i;
}
Page.Application.Window.DeselectAll();
shape = Page.Shapes["Number 3"];
Page.Application.Window.Select(shape,
(short)Visio.VisSelectArgs.visSelect);

I get a COM exception "Requested operation is presently disabled" on
the call to Select(). The shapes draw just fine if I leave out the
Select().

Is there something I need to do to make Visio finish creating the new
shapes before I can select them?

Thank you for any suggestions you can give me.
 
M

Mark Nelson [MS]

Adding a shape to a page automatically selects it. You don't need to write
code for that.
 
L

Larry F.

Thanks for the reply. I should have been more explict. I need to draw
several shapes and then select them all so I can group them, but it
seems that I can't immediately select newly-drawn shapes without
giving Visio time to finish up the drawing process. How do I let Visio
finish with what it is doing so I can select all the new shapes?
 
H

Heidi Munson [MSFT]

Window property of the Application object is not a drawing window. It is
the frame window for the application in standalone Visio.exe.
Application.Window.Select will always fail.

Drawing windows are in Application.Windows collection. Use the .Type and
..SubType properties to determine if its a drawing window and the type of
drawing window.

In the drawing control, the drawing window for the control instance is the
..Window property of the DrawingControl object.

The Visio SDK has a ActiveX control sample that shows how to select shapes
in the control window and shows how to handling Visio NoEventsPending event
which fires when Visio is done processing.
You can download the Visio 2003 SDK here,
http://www.microsoft.com/downloads/...bd-b0bb-46e7-936a-b8539898d44d&displaylang=en

-Heidi
Microsoft Corp

This posting is provided "AS IS" with no warranties, and confers no rights



Larry F. said:
Thanks for the reply. I should have been more explict. I need to draw
several shapes and then select them all so I can group them, but it
seems that I can't immediately select newly-drawn shapes without
giving Visio time to finish up the drawing process. How do I let Visio
finish with what it is doing so I can select all the new shapes?


"Mark Nelson [MS]" <[email protected]> wrote in message
Adding a shape to a page automatically selects it. You don't need to write
code for that.
 
L

Larry F.

Thanks for the responses. Maybe I should have guessed that the
Application.Window is not a drawing window. I guess I expected the
compiler to catch that sort of mistake, or at least get a helpful
runtime exception.

Also, if anyone else gets the "Requested operation is presently
disabled" exeption when trying to select shapes, make sure that
ShowChanges isn't false. You can turn off ScreenUpdating and still
select, but turning off ShowChanges and trying to select throws that
not-very-helpful message. Why couldn't they throw a "You idiot! Don't
Select when ShowChanges is false!" exception? It seems the Visio
developers saved a little time by over-using a few exceptions, but
they have cost me a full day. Shame on them.

Thanks again.
 

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