如何使用RichTextBox在visual studio中创建documents.docx readOnly?

时间:2014-05-12 05:25:01

标签: c# winforms richtextbox

这是我的代码,当它是调试时,文档将在Rich TextBox中打开,但它可以编辑,所以我需要它是ReadOnly。你可以帮帮我吗。

void ImportWord()
{
    Microsoft.Office.Interop.Word.Application wordObject = new Microsoft.Office.Interop.Word.Application();
    object File = @"C:\Users\czu_ecu\Desktop\OAG-WORK\Management_Letter_Template1.docx" ; //this is the path
    object nullobject = System.Reflection.Missing.Value; Microsoft.Office.Interop.Word.Application wordobject = new Microsoft.Office.Interop.Word.Application();
    wordobject.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone; Microsoft.Office.Interop.Word._Document docs = wordObject.Documents.Open(ref File, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject); docs.ActiveWindow.Selection.WholeStory();
    docs.ActiveWindow.Selection.Copy();
    this.richTextBox2.Paste();
    docs.Close(ref nullobject, ref nullobject, ref nullobject);
    wordobject.Quit(ref nullobject,ref nullobject, ref nullobject);
}

private void btnTemML_Click(object sender, EventArgs e) //Handles the actions of the template button
{
    btnAdd_Finding.Visible = false;
    listView2.Visible = false;
    label8.Visible = false;
    richTextBox1.Visible = false;
    listView1.Visible = false;
    listView3.Visible = false;
    richTextBox2.Visible = true;

    ImportWord();

    listView1.Items.Clear();
}

1 个答案:

答案 0 :(得分:1)

您可以尝试以下代码。

richTextBox2.Visible = true;
richTextBox2.IsReadOnly = true;