我有一个接受用户输入的richtextbox。当单击“cetak”(打印)按钮时,输入将转到Ms Words。
我想在Words中显示输入,因为输入fontstyle将更改为下划线。
例如用户输入:Jessica
单词输出:Jessica(带下划线)
Public Class Form1
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Dim ps As New PageSettings
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oPara1 As Word.Paragraph
'Start Word and open the document template.
oWord = CreateObject("Word.Application")
oWord.Visible = False
oDoc = oWord.Documents.Add
oDoc.PageSetup.Orientation = Word.WdOrientation.wdOrientPortrait
Dim rng As Word.Range = oDoc.Paragraphs(1).Range
rng.Font.Size = 10
oDoc.Paragraphs.LineSpacingRule = Word.WdLineSpacing.wdLineSpaceSingle
RichTextBox1.Text = RichTextBox1.Text.ToUpper
oPara1 = oDoc.Content.Paragraphs.Add
oPara1.Range.Font.ColorIndex = Word.WdColorIndex.wdBlack
oPara1.Range.Text = "Try: " & RichTextBox1.Text
oPara1.Range.InsertParagraphAfter()
oWord.Visible = True
oDoc.PrintPreview()
End Sub
End Class
答案 0 :(得分:0)
来自你的评论:
如果我把这个编码放在oPara1.Range.Font.Underline = Word.WdUnderline.wdUnderlineSingle整个段落都是下划线 包括'尝试:'。我希望输入只是下划线
是的文字会加下划线,因为您将段落设置为"尝试:"和RichTextBox1内容
您的代码:
oPara1.Range.Text = "Try: " & RichTextBox1.Text
所以为了实现你的目标,即。 :
使用下面的代码为richtextbox中的内容加下划线,然后导出到word:
RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Underline)
并将其导出到word应用程序。