public void InsertText( string strText)
{
oWordApplic.Selection.TypeText(strText);
}
public void InsertLineBreak( )
{
oWordApplic.Selection.TypeParagraph();
}
public void InsertLineBreak( int nline)
{
for (int i=0; i<nline; i++)
oWordApplic.Selection.TypeParagraph();
}
public void SetAlignment(string strType )
{
switch (strType)
{
case "Center" :
oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
break;
case "Left" :
oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
break;
case "Right" :
oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
break;
case "Justify" :
oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify;
break;
}
}
public void SetFont( string strType )
{
switch (strType)
{
case "Bold":
oWordApplic.Selection.Font.Bold = 1;
break;
case "Italic":
oWordApplic.Selection.Font.Italic = 1;
break;
case "Underlined":
oWordApplic.Selection.Font.Subscript = 0;
break;
}
3、废话不说了,看我的程序吧!
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
public class CCWordApp
{
private Word.ApplicationClass oWordApplic; // a reference to Word application
private Word.Document oDoc; // a reference to the document
Insert Plain Text and Images into RichTextBox at Runtime
http://www.codeproject.com/cs/miscctrl/csexrichtextbox.asp
注册下载:
http://www.codeproject.com/cs/miscctrl/CsExRichTextBox/ExRichTextBox_src.zip