【问题标题】:How to place label next to a checkbox control in Interop Word如何在 Interop Word 中的复选框控件旁边放置标签
【发布时间】:2016-10-13 09:37:15
【问题描述】:

如何并排放置 2 个项目,例如一个复选框和一个标签,而不在 Interop Word 中创建新行?

这是我正在使用的代码。这是一个新行,因为我将每个项目放在一个段落中。怎么做到一行?

 //CheckBox
 Word.Paragraph checkBoxparagraph = document.Paragraphs.Add(ref missing);
 Word.ContentControl checkbox = checkBoxparagraph.Range.ContentControls.Add(Word.WdContentControlType.wdContentControlCheckBox);
 checkBoxparagraph.Range.InsertParagraphBefore();

//Label
Word.Paragraph label = document.Paragraphs.Add(ref missing);
label.Range.Text = "Checkbox Label";
label.Range.InsertParagraphAfter();

这是代码的输出:

【问题讨论】:

    标签: c# interop office-interop com-interop


    【解决方案1】:

    也许有更好的方法,但我会将它包装成内联形状。很抱歉没有费心将其转换为 C#,但您应该了解它的要点。如果您喜欢该解决方案,您可能想要修改文本框的样式、高度和宽度

    Sub CheckBoxLabel()
        Dim oDoc As Document
        Dim textBox As Shape
        Dim oRng As Range
    
        Set oDoc = ActiveDocument
        Set oRng = oDoc.Paragraphs(1).Range
    
        oRng.Text = "My label"
    
        Set textBox = oDoc.Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 0, 40, 40, oRng.Characters(1))
        textBox.ConvertToInlineShape
        Set checkBox = textBox.TextFrame.TextRange.ContentControls.Add(wdContentControlCheckBox)
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2021-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-15
      相关资源
      最近更新 更多