【问题标题】:Replace Image/shape in visio c#在visio c#中替换图像/形状
【发布时间】:2017-05-16 05:02:06
【问题描述】:

我正在使用以下代码将 jpeg 图像拖放到 Visio 绘图页上,但是每次我运行我的应用程序时,我放置的图像都会放置在我之前放置的图像之上。我的问题是如何替换图像/形状,以便用新图像替换较早的图像。 我尝试使用 shpNew.ReplaceShape(imageFile, 0);但它再次与之前的图像重叠。

我的另一个想法是删除早期的形状并删除新图像。 请让我知道有效的方法。

private void DropImage(Visio.Page vPag, string imageFile)
    {
        if (vPag != null)
        {
            var shpNew = vPag.Import(imageFile);
            //Set position
            shpNew.CellsU["PinX"].FormulaU = "75mm";
            shpNew.CellsU["PinY"].FormulaU = "175mm";
            //Set size
            shpNew.CellsU["Width"].FormulaU = "100mm";
            shpNew.CellsU["Height"].FormulaU = "80mm";
        }
    }

【问题讨论】:

    标签: c# replace automation visio


    【解决方案1】:

    ReplaceShape 方法适用于基于母版的形状!!!

    Shape.ReplaceShape 方法 (Visio)

    将指定的形状替换为作为 第一个参数,并返回新的形状。

    适用于所有 visio 形状和外来对象,例如插入的图像 https://msdn.microsoft.com/en-us/library/office/jj229596.aspx?f=255&MSPPError=-2147217396

    【讨论】:

    • 感谢您的信息。如果不支持 Replace 方法,我可以知道如何删除或删除我插入的较早的图像,以便删除较新的图像,如 c# 中的 VBA 的 shpNew.delete?
    • 我总是每页放一张图片
    【解决方案2】:

    我找到了你以前的帖子:Insert an Jpeg/bmp image onto the visio drawing using VBA/C#

    Sub v()
        Dim shp As Shape
        Dim os As Shape
        Dim ns As Shape
        Dim x As Single, y As Single
        For Each shp In ActivePage.Shapes
        ' find images
        If shp.Type = 4 Then
        ' define os variable as founded image
        Set os = shp
        End If
        Next
        If IsEmpty(os) Then
        MsgBox "Picture not found"
        Else
        ' define X and Y position
        x = os.Cells("PinX")
        y = os.Cells("Piny")
        ' insert new picture
        Set ns = ActivePage.Import("c:\Users\Surrogate\Desktop\ycnex.png")
        ' place new shape to old shape coordinates
        ns.Cells("pinx") = x
        ns.Cells("piny") = y
        ' delete old shape
        os.Delete
        End If
        End Sub

    【讨论】:

      猜你喜欢
      • 2012-08-04
      • 2014-10-30
      • 1970-01-01
      • 2022-11-12
      • 2015-01-17
      • 2013-11-04
      • 2018-04-06
      • 1970-01-01
      • 2016-01-13
      相关资源
      最近更新 更多