问题描述
在 Visio 页面上的 Visio 形状上,将 Office 加载项功能添加到 Visio 形状上的右键单击鼠标菜单的唯一方法是使用
在右键单击菜单中的此形状上,您将找到测试"菜单项.运行这个项目,一个新的方形将被添加到页面中.
现在使用撤消,然后执行重做.如果您移动新形状,您将看到其下方有一个相同的方形.重做不会添加一个,而是添加两个新形状.
我想我对 QueueMarker 事件的工作方式有一些误解我只是一个业余开发人员,希望有人知道如何稳健地解决这个问题,因为可靠的撤消/重做行为对于一个好的加载项应用程序非常重要.感谢您分享您的见解!
导入 System.Windows.Forms导入系统.诊断导入 System.Text导入 Visio = Microsoft.Office.Interop.Visio部分公共类 ThisAddInPrivate Sub Application_MarkerEvent(app As Visio.Application, SequenceNum As Integer, ContextString As String) 处理Application.MarkerEventDim Stencil As Visio.Document模板 = GetStencil()如果 Stencil 什么都不是,那么MessageBox.Show(基本形状模板已关闭,请在运行此操作前将其打开.")退出子万一Dim Square As Visio.ShapeSquare = Application.ActivePage.Drop(Stencil.Masters.ItemU(Square"), 0, 0)结束子私有函数 GetStencil() 作为 Visio.DocumentDim DocCounter 一样长对于 DocCounter = 1 到 Application.Documents.Count如果 Application.Documents(DocCounter).Type = Visio.VisDocumentTypes.visTypeStencil 那么如果 Application.Documents(DocCounter).Name = "BASIC_M.vssx";或 Application.Documents(DocCounter).Name = "BASIC_U.vssx";然后'MessageBox.Show(Application.Documents(DocCounter).Name)返回 Application.Documents(DocCounter)退出函数万一万一下一个 DocCounter什么都不返回结束函数结束类
我认为 MarkerEvent 在 Redo 上生成了两次.您能否检查 ContextString 是否为 ==Test"?在处理它之前看看它是否有帮助?
On Visio shapes on a Visio page, the only way to add Office Add-in functionality to the right-click mouse menu on Visio shapes is to use the QUEUEMARKEREVENT shapesheet function.
Unfortunately, this way of letting the user use functionality on a Visio shape is causing issues with the Undo/Redo system.
I have made some sample code below that can be dropped in to a new Visio VSTO VB.NET Project in Visual Studio (I use 2019, Visio also version 2019)
Compile the VSTO add-in and when Visio starts up, choose a Basic Diagram as that opens up the stencil I use for the test.
Drop one shape on the page and edit the ShapeSheet to add an Action Section, as per this screenshot:
On this shape in the right-click menu you will find the "Test" menu item. Run this item and a new Square shape will be added to the page.
Now use Undo and then perform a Redo. If you move the new shape you will see there is an identical square shape below it. A Redo doesn't add one but actually two new shapes.
I think I am misunderstanding something about how the QueueMarker events work I am very much just an amateur developer, hopefully someone knows how to fix this robustly as reliable Undo/Redo behavior is very important for a good add-in application. Thank you for sharing your insights!
Imports System.Windows.Forms
Imports System.Diagnostics
Imports System.Text
Imports Visio = Microsoft.Office.Interop.Visio
Partial Public Class ThisAddIn
Private Sub Application_MarkerEvent(app As Visio.Application, SequenceNum As Integer, ContextString As String) Handles Application.MarkerEvent
Dim Stencil As Visio.Document
Stencil = GetStencil()
If Stencil Is Nothing Then
MessageBox.Show("The Basic Shapes stencil is closed, please open it before running this action.")
Exit Sub
End If
Dim Square As Visio.Shape
Square = Application.ActivePage.Drop(Stencil.Masters.ItemU("Square"), 0, 0)
End Sub
Private Function GetStencil() As Visio.Document
Dim DocCounter As Long
For DocCounter = 1 To Application.Documents.Count
If Application.Documents(DocCounter).Type = Visio.VisDocumentTypes.visTypeStencil Then
If Application.Documents(DocCounter).Name = "BASIC_M.vssx" Or Application.Documents(DocCounter).Name = "BASIC_U.vssx" Then
'MessageBox.Show(Application.Documents(DocCounter).Name)
Return Application.Documents(DocCounter)
Exit Function
End If
End If
Next DocCounter
Return Nothing
End Function
End Class
I think the MarkerEvent is generated twice on Redo. Can you check for the ContextString to be == "Test" before processing it and see if it helps?
这篇关于来自 shapesheet 用户操作的 Visio VSTO Add-in QueueMarker 事件,添加一个形状但在重做时获得两个形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!