Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 单词VSTO-如何填充形状上的效果?_Vb.net_Ms Word_Vsto_Shape_Fill - Fatal编程技术网

Vb.net 单词VSTO-如何填充形状上的效果?

Vb.net 单词VSTO-如何填充形状上的效果?,vb.net,ms-word,vsto,shape,fill,Vb.net,Ms Word,Vsto,Shape,Fill,我使用以下代码在Word文档中插入一个形状(矩形) Dim oShpWidth As Single Dim oShpHght As Single Dim oShpTop As Single Dim oShpLeft As Single With Globals.ThisAddIn.Application.ActiveDocument oShpWidth = 225.1 oShpHght = 224.5 oShpTop = 0 oShpLef

我使用以下代码在Word文档中插入一个形状(矩形)

Dim oShpWidth As Single
Dim oShpHght As Single
Dim oShpTop As Single
Dim oShpLeft As Single
With Globals.ThisAddIn.Application.ActiveDocument
    oShpWidth = 225.1
        oShpHght = 224.5
        oShpTop = 0
        oShpLeft = 0
        .Shapes.AddShape(1, 0, 0, oShpWidth, oShpHght).Select()

        With Globals.ThisAddIn.Application.Selection.ShapeRange
            .Rotation = 0.0#
                .RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionCharacter
                .RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionLine
                .Left = oShpTop
                .Top = oShpLeft
        End With
End With

但我也喜欢将背景颜色更改为无颜色,将线条颜色更改为无颜色,并使用填充效果通过代码添加图片。如何实现这一点?

我恐怕下面是C语言,但您应该能够相当轻松地转换为VB.Net

using System;
using Word = Microsoft.Office.Interop.Word;
using System.Drawing;


namespace WordAddIn
{
    public class ImageTest
    {
       internal void InsertTextBoxWithPicture()
       {
           Word.Application app = Globals.ThisAddIn.Application;
           Word.Document doc = app.ActiveDocument;

           Word.Shape shape1 = doc.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, app.CentimetersToPoints(2.45f),
            app.CentimetersToPoints(1.25f), app.CentimetersToPoints(9.2f), app.CentimetersToPoints(2.5f));
           shape1.TextFrame.MarginLeft = 0f;
           shape1.TextFrame.MarginRight = 0f;
           shape1.TextFrame.MarginTop = 0f;
           shape1.TextFrame.MarginBottom = 0f;
           shape1.Fill.BackColor.RGB = ColorTranslator.ToOle(Color.Transparent);
           shape1.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
           shape1.Fill.Transparency = 0f;
           shape1.Line.Transparency = 0f;
           shape1.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
           Word.Range range = shape1.TextFrame.TextRange;
           range.InlineShapes.AddPicture(@"C:\Users\Public\Pictures\Sample Pictures\Koala.jpg", false, true, Type.Missing);
       }

       internal void InsertShapeWithPicture()
       {
           Word.Application app = Globals.ThisAddIn.Application;
           Word.Document doc = app.ActiveDocument;
           Word.Shape shape = doc.Shapes.AddShape(1, 0f, 0f, 225.1f, 224.5f);
           shape.Fill.BackColor.RGB = ColorTranslator.ToOle(Color.Transparent);
           shape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
           shape.Fill.Transparency = 0f;
           shape.Line.Transparency = 0f;
           shape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;

           Word.Range range1 = shape.TextFrame.TextRange;
           range1.InlineShapes.AddPicture(@"C:\Users\Public\Pictures\Sample Pictures\Koala.jpg", false, true, Type.Missing);

        }
    }
}
在C#中,必须显式声明浮点,因此
0f
等。上述方法之一应该可以实现此目的。

,请检查此问题:。提前谢谢。嘿,我还有一个类似的问题。请查收: