Context Menu Functions in .NET client

N

Neil Konitzer

We are using the Visio Drawing Control (2003) in a VS.NET client
application. We have added a menu item to one of the context menus. What
is the correct method for calling a WinForms function or sub procedure
when the menu item is clicked? It appears that the only acceptable
methods are VBA macros or functions.

Thanks in advance!

~Neil Konitzer
 
J

junethesecond

I have not .Net.
But, visio.addons may be acceptable methods.
If so, and if you add your addon to addons.
 
M

Markus Breugst

Hi Neil,

We are not using the ActiveX control. However, our way of handling context
menus may be applicable for you:

1. We have inserted a User property into the shape. Let's say its name is
"User.ACTION_NUMBER".
2. We inserted the following formula into the "Action" column of the context
menu table: "SETF(GetRef(User.ACTION_NUMBER);22)" where 22 is known by our
..NET application as the number of a specific context menu function.

Now, when you click on the context menu item, Visio puts the value 22 into
the cell "User.ACTION_NUMBER". This fires a CellChanged event.
Our application receives this event, reads the new cell value 22 and
processes the function that is associated with this number.

Best regards,
Markus
 
N

Neil Konitzer

I think that there is something that I am missing here. For some reason,
the cell changed event is not being raised when I select the menu item
from the context menu item. If I manually go and change the user
property in the drawing control, then the cell changed event is firing
and I am able to do what I need to do.

I have the ActionText property set to...

SETF(GetRef(User.Action);1)

Am I missing anything else? What about the AddonName property? I am not
sure if this is indeed a required property value and if so, what value
needs to go in here for a .NET client?
 
M

Markus Breugst

Hi Neil,

have you checked that your User.Action property is really changed when you
click onto the context menu item? In this case there should not be any
difference between changing the cell value directly or via the context menu.
The formula is corrent. However, I'm not sure what you mean with
"ActionText".
The Action table has a column named "Action", and this is the column for
your formula.

One thing more: You are using a semicolon in your formula. This is correct
for the English version of Visio. If you are using a German version, try a
comma instead.
(Usually, using a semicolon in the German version would raise an error.
However, perhaps you have put your formula in quotation marks(?) In this
case, no error is raised, and Visio just ignores the formula if it cannot be
interpreted.)

Hope this helps.

Best regards,
Markus
 
N

Neil Konitzer

We are programmatically adding menu items to the Context Menus at
run-time. In this case, the "ActionText" property is what is supposedly
used for stating the action formula. We are not modifying the menus at
design time.

Do you think that we have no choice but to design the context menus for
each shape beforehand, and not at run-time?
 
M

Markus Breugst

Do you think that we have no choice but to design the context menus for
each shape beforehand, and not at run-time?

No, you can modify the Action section during runtime. We also do this for
some of the menus. Here is our code that does the job. The parameter
'action' must contain the formula. The parameter 'menu' provides the text of
the menu item.

Hope this helps.

Best regards,
Markus

public static void AddActionToShape( IVShape vShape, string action,
string menu, short rowIndex )
{
IVCell _vCell;

if (vShape.get_SectionExists( (short)
VisSectionIndices.visSectionAction, 1 ) == 0)
{
vShape.AddSection( (short)
VisSectionIndices.visSectionAction );
}

vShape.AddRow( (short) VisSectionIndices.visSectionAction,
rowIndex, (short) VisRowTags.visTagDefault );
_vCell = vShape.get_CellsSRC( (short)
VisSectionIndices.visSectionAction, rowIndex, (short)
VisCellIndices.visActionAction );
_vCell.Formula = action;
_vCell = vShape.get_CellsSRC( (short)
VisSectionIndices.visSectionAction, rowIndex, (short)
VisCellIndices.visActionMenu );
_vCell.Formula = "=\"" + menu + "\"";
}
 
N

Neil Konitzer

Thanks again, Markus! We're definitely getting closer. However, we are
getting a COM error when trying to set the value of the action formula
using the "SETF(GetRef(User.Action; 1)" format. We get a #NAME error.
We'll keep playing with this.
 
N

Neil Konitzer

Markus,
Thanks for the help with this. The #Name error was a result of not
having the cell name spelled correctly. Your solution has us up and running!
 

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