C# Visio 容器 [英] C# Visio Containers

查看:24
本文介绍了C# Visio 容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使用 C# 获取容器的内容(子项).如果只是在页面上绘制,效果很好,但是一旦转换为母版,它就不再被识别为容器".

I am struggling getting to the contents (children) of a Container using C#. Works fine if just drawn on the page, but once converted to a master, it is no longer recognized as a 'container'.

所以,例如.从插入"选项卡创建一个新容器.在主页"选项卡中,在容器中绘制 2 个矩形,在每个矩形中键入一些文本,然后添加到基础容器".

So, for example. Create a new container from the 'Insert' tab. From the 'Home' tab, draw 2 rectangles in the container, type some text in each, and then 'add to underlying container'.

在此之后,下面的代码报告了 2 个矩形 Names &文本.

After this, the code below reports the 2 rectangle Names & Texts.

但是,我现在将容器拖到我的模具中以创建母版.然后我将母版拖到页面上以创建一个实例.

However, I now drag the container into my stencil to create a master. Then I drag the master to the page to create an instance.

现在代码根本找不到任何 MemberShapes.

Now the code does not find any MemberShapes at all.

我做错了什么?任何建议/指导表示赞赏!

What am I doing wrong ? Any advice/guidance appreciated !!

    foreach (Microsoft.Office.Interop.Visio.Shape shape in Globals.ThisAddIn.Application.ActivePage.Shapes)
                {

                    System.Diagnostics.Debug.WriteLine(shape.Name);

                    if (shape.ContainerProperties != null) {
                        foreach (int memberID in shape.ContainerProperties.GetMemberShapes(0)) {
                            Microsoft.Office.Interop.Visio.Shape vsoShape = Globals.ThisAddIn.Application.ActivePage.Shapes.ItemFromID[memberID];
                            Debug.Print(vsoShape.Name);
                            Debug.Print(vsoShape.Text);
                        }
                    }
}

推荐答案

我怀疑是你的主创给你带来了麻烦.如果您将新容器拖到文档模板上以创建母版,则成员形状会随之而来.但是,Visio 喜欢将母版分组,如果不是,它会将它们分组.如果您取消对新实例形状(容器和成员)的分组,然后再次运行您的代码,它应该按预期报告.这样做的问题是它断开了与主人的链接.

It's your master creation that's giving you trouble I suspect. If you drag your new container onto your doc stencil to create a master the member shapes come along for the ride. However, Visio likes masters to be grouped and if they're not it will group them on drop. If you ungroup your new instance shape (container and members) and then run your code again it should report as expected. The problem with this is that it breaks the link with the master.

我认为您需要将形状分解为单独的成员和容器主控.

I think you'll need to break up your shapes up into separate member and container masters.

如果您要删除列表类型的容器形状,则可以使用 User.msvSDListItemMaster + EventDrop 组合指示 Visio 删除其他列表项形状.(请参阅 Visio 2010 中的自定义容器、列表和标注 以获取更多详细信息.)不幸的是,这不适用于直容器形状,因为新成员的放置位置形状未知.

If you were dropping a List type container shape then you could instruct Visio to drop additional list item shapes using the User.msvSDListItemMaster + EventDrop combo. (See "Specifying a shape to insert into lists" section of the Custom Containers, Lists and Callouts in Visio 2010 post for more details.) Unfortunately this doesn't work for straight container shapes as the drop position of the new member shapes isn't known.

如果您想要一个预填充的容器,那么一种选择是在代码中侦听放置事件并在处理程序中添加新成员,或者从 EventDrop 单元格中使用 QUEUEMARKEREVENT ShapeSheet 函数触发 MarkerEvent.同样,这意味着您需要监听和处理应用程序标记事件.

If you want to have a prepopulated container then one option would be to either listen for the drop event in code and add the new members in the handler, or, fire a MarkerEvent with the QUEUEMARKEREVENT ShapeSheet function from the EventDrop cell. Again, this implies that you'll then need to be listening for and process Application Marker Events.

我不知道您对 Visio 事件有多熟悉,但我在此处找到的视频的代码部分中介绍了它们:

I don't know how familiar you are with Visio events, but I covered them in the code part of the videos found here:

http://visualsignals.typepad.co.uk/vislog/2016/04/new-visio-training-videos.html

2017 年 12 月 13 日更新 - 还添加了相关的课程文件帖子,课程中使用了哪些演示代码:

Update 13th Dec 2017 - adding associated course files post as well, which demos code used in course:

http://visualsignals.typepad.co.uk/vislog/2017/01/course-files-for-visio-flyby-for-developers-on-ch9.html

这篇关于C# Visio 容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆