Author Topic: VSTO Addin example for marker event handling in vb.net  (Read 2926 times)

0 Members and 1 Guest are viewing this topic.

Visisthebest

  • Sr. Member
  • ****
  • Posts: 376
VSTO Addin example for marker event handling in vb.net
« on: December 10, 2020, 07:19:21 AM »
I installed the Visio 2016 SDK but unfortunately the examples haven’t been updated much, the Treeview Visual Studio example for vb.net contains  marker event handling example code but is for VS 2010/2012 with an old installer project that doesn’t work in 2017/2019.

Do you know a more recent example VS 2017/2019 VSTO project on github that allows me to learn from a good example of how to handle marker events coming in from the shapesheet?

A recent C# example is also super of course, it is important to learn from a good example of solidly handling marker events in an add-in.

Thank you very much!
Visio 2021 Professional

Nikolay

  • Hero Member
  • *****
  • Posts: 1056
    • UnmanagedVisio
Re: VSTO Addin example for marker event handling in vb.net
« Reply #1 on: December 10, 2020, 08:40:37 AM »
This looks simple. You just add a method to your app class like this:

Code
Public Class ThisAddIn

    Private Sub Application_MarkerEvent(app As Application, SequenceNum As Integer, ContextString As String) Handles Application.MarkerEvent
        System.Windows.Forms.MessageBox.Show(ContextString)
    End Sub
(check if the context string is "yours" and then do whatever you need based on that)

In Visio you just call


Just in case, pushed simplest sample (sample Visio file is included) ;D
https://github.com/nbelyh/QueueMarkerEventSample

BTW, why do you want to call add-in from ShapeSheet (maybe you are facing XY problem?) - this is unusual (for context menu for example, you can use ribbon instead)
« Last Edit: December 10, 2020, 08:55:12 AM by Nikolay »

Visisthebest

  • Sr. Member
  • ****
  • Posts: 376
Re: VSTO Addin example for marker event handling in vb.net
« Reply #2 on: December 10, 2020, 08:57:27 AM »
Thank you so much Nikolay!

I use the context menu to keep an identical UI between the VBA version and the add-in version, but yes adding a ribbon for the add-in improves the UI, will have to figure out how to only show relevant functionality depending on the shape selected.
Visio 2021 Professional

Nikolay

  • Hero Member
  • *****
  • Posts: 1056
    • UnmanagedVisio
Re: VSTO Addin example for marker event handling in vb.net
« Reply #3 on: December 10, 2020, 09:01:55 AM »
If you already do have the menus, then it makes sense, of course. With ribbon, it would be more complicated.
But theoretically you can define context menus there as well, and show/hide and disable/enable them dynamically.

Hope the sample helps.

Visisthebest

  • Sr. Member
  • ****
  • Posts: 376
Re: VSTO Addin example for marker event handling in vb.net
« Reply #4 on: December 10, 2020, 09:05:13 AM »
Yes very helpful thank you Nikolay!
Visio 2021 Professional

Visisthebest

  • Sr. Member
  • ****
  • Posts: 376
Re: VSTO Addin example for marker event handling in vb.net
« Reply #5 on: May 01, 2021, 03:07:46 AM »
Hi Nikolay,

Thank you the example vs project and code work fine. When I paste the marker event handler line in to the solution you created for Visio add-ins, I get this warning on the Handles Application.Markerevent:

Severity   Code   Description   Project   File   Line   Suppression State
Warning   BC42322   Runtime errors might occur when converting 'Application' to 'Application'.   ExtendedVisioAddin1

Do you have an idea for the why of this warning and how I can resolve the issue? Better to understand warnings that may cause issues later, especially if I don't understand why I get them.

Thank you!

This looks simple. You just add a method to your app class like this:

Code
Public Class ThisAddIn

    Private Sub Application_MarkerEvent(app As Application, SequenceNum As Integer, ContextString As String) Handles Application.MarkerEvent
        System.Windows.Forms.MessageBox.Show(ContextString)
    End Sub
(check if the context string is "yours" and then do whatever you need based on that)

In Visio you just call


Just in case, pushed simplest sample (sample Visio file is included) ;D
https://github.com/nbelyh/QueueMarkerEventSample

BTW, why do you want to call add-in from ShapeSheet (maybe you are facing XY problem?) - this is unusual (for context menu for example, you can use ribbon instead)
« Last Edit: May 01, 2021, 03:10:47 AM by Visisthebest »
Visio 2021 Professional

Nikolay

  • Hero Member
  • *****
  • Posts: 1056
    • UnmanagedVisio
Re: VSTO Addin example for marker event handling in vb.net
« Reply #6 on: May 01, 2021, 07:29:26 AM »
Could you share the project?

I mean, if I build the sample I shared, it seems I don't get this warning: https://github.com/nbelyh/QueueMarkerEventSample

Visisthebest

  • Sr. Member
  • ****
  • Posts: 376
Re: VSTO Addin example for marker event handling in vb.net
« Reply #7 on: May 01, 2021, 10:35:52 AM »
Thank you Nikolay currently travelling will send you the project files when I’m back at my pc Monday.

The queuemarker events work fine this warning notwithstanding but still an odd error.
Visio 2021 Professional

Visisthebest

  • Sr. Member
  • ****
  • Posts: 376
Re: VSTO Addin example for marker event handling in vb.net
« Reply #8 on: May 02, 2021, 01:55:34 AM »
Nikolay please see your e-mail at support@unmanagedvisio.com for the project files. Hope you have an idea why this warning occurs!

Visio 2021 Professional

dmbalzer

  • Jr. Member
  • **
  • Posts: 16
Re: VSTO Addin example for marker event handling in vb.net
« Reply #9 on: May 04, 2021, 10:33:04 AM »
Would doing this in C# be just as simple as adding a method to the ThisAddin Class?

Visisthebest

  • Sr. Member
  • ****
  • Posts: 376
Re: VSTO Addin example for marker event handling in vb.net
« Reply #10 on: May 04, 2021, 10:59:13 AM »
dmbalzer Nikolay found out that because WinForm is used this is also an application and Visual Studio needs Visio.Application not just Application to disambiguate the statement (it might mean the WinForm application after all).

Visio 2021 Professional