2012-12-19 29 views
1

我得到一個錯誤"File Format is not valid"當我追加RTF到richtextbox如何附加trow到richtextbox?

 public void Go() 
     { 
      rtb.Text = "Activated Partial Thromboplastin Time : Collected: 8/17/2012 9:06:00 AM\n"; 

      rtb.Select(rtb.TextLength, 0);//sets the selection starting point as the end of this Rtb 
      rtb.SelectedRtf = @"{\trowd" +//ERROR thrown here 
@"\cellx4000" + 
@"\cellx9500" + 
@"\intbl Activated Partial Thromboplastin Time\cell" + 
@"\intbl 34.8 Seconds\cell" + 
@"\row}"; 
} 

我怎麼能追加trowd我的RichTextBox?

回答

2

要插入RTF代碼,它必須是一個完全獨立的RTF文件,這意味着你需要的\rtf1{頁眉和關閉}符號添加到您的文字:

rtb.SelectedRtf = @"{\rtf1\ansi{\trowd" +//ERROR thrown here 
@"\cellx4000" + 
@"\cellx9500" + 
@"\intbl Activated Partial Thromboplastin Time\cell" + 
@"\intbl 34.8 Seconds\cell" + 
@"\row}}"; 

請注意字符串的開頭並在最後加上額外的}支架。

+0

因此,不可能將RTF附加到文本?我只能替換整個內容。 –

+1

@ P.Brian.Mackey不知道我關注。我修改了代碼以使其工作 - 它在rtf文檔的末尾插入表格行。 SelectedRtf屬性要求該值是一個有效的rtf實體,它需要'{\ rtf1 \ ansi}'格式。所以不,你不能取代整個內容,只是SelectedRtf部分。 – LarsTech

+0

我的錯誤,謝謝澄清。 –