Visio Guy

Visio Discussions => Programming & Code => Topic started by: Visisthebest on February 25, 2021, 12:08:49 PM

Title: Learning how to make context-sensitive ribbon icons in add-in
Post by: Visisthebest on February 25, 2021, 12:08:49 PM
Slowly but surely I am learning how to develop a Visio add-in with Visio and VB.NET, still getting used to the differences between VBA and Visual Studio and Office VSTO for sure.

I am now getting to the adding Ribbons and ribbon icons (I think of them as buttons) to the add-in, and wondering what is the best way to go about creating context-sensitivity.

In terms of what I want to accomplish, when a user clicks a certain shape depending on the shape type I want to show different icons (so irrelevant functionality is not shown, because those icons/buttons will be 'dead' in this context, have to give the user a warning that he's selected the wrong shape for this functionality, not a good UI experience). What is the best, most solid way to do this in a Visio add-in?

Thank you for your help!


Title: Re: Learning how to make context-sensitive ribbon icons in add-in
Post by: Visisthebest on February 26, 2021, 11:34:59 AM
Ok, so for me the easiest way to deal with this is to add a RibbonTab for my add-in, and then group the context-sensitive ribbon buttons in groups.

Depending on which shape is selected, I set Visible = true/false on the RibbonGroups depending on the shape selected.

Are there good code uptodate code examples for capturing selection events (I understand advice is to use AddAdvise because it is less 'chatty'), then I can quickly assess what shape type is selected and set the RibbonGroup visibility accordingly.

Event handling in an add-in is not an easy thing no doubt, so advice on how to set it up well is appreciated thank you!
Title: Re: Learning how to make context-sensitive ribbon icons in add-in
Post by: Visisthebest on February 26, 2021, 11:53:03 AM
So I need to capture SelectionChanged, need to adapt this VBA code:
https://docs.microsoft.com/en-us/office/vba/api/visio.eventlist.addadvise

to a .NET add-in, should be able to figure this out.