3
我有一個RichTextBox的WinForms應用程序。我希望能夠在我的應用程序中剪切,複製和粘貼格式化文本。目前,我的代碼包括:如何剪切,複製和粘貼格式?
剪切所有:
richTextBoxPrintCtrl1.Cut();
剪切選定:
Clipboard.SetText(richTextBoxPrintCtrl1.Text);
richTextBoxPrintCtrl1.Text = "";
全部複製:
richTextBoxPrintCtrl1.Copy();
複製選定:
Clipboard.SetDataObject(richTextBoxPrintCtrl1.SelectedText);
粘貼:
DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.Text);
richTextBoxPrintCtrl1.Paste(myFormat);
我想這麼說,如果我剪切/複製文本從RichTextBox的,它保留了所有格式(大小,字體,顏色等),如果我粘貼文本到RichTextBox中,它也保持所有格式。
這將如何實現?
謝謝。
乾杯。你有什麼想法我可以得到複製全部工作?我試過Clipbiard.SetText(richTextBoxPrintCtrl1.SelectAll.Rtf,TextDataFormat.Rtf),但那不起作用。 – Toby 2013-04-10 11:22:08
@Toby:你必須使用Clipboard.SetText(richTextBox1.Rtf,TextDataFormat.Rtf);這將獲得與格式的所有文字,我已經嘗試this.it的工作很好 – KF2 2013-04-10 11:30:59
哦,好吧。它只是使用richTextBoxPrintCtrl1.Copy();無論是否被選中,都將從RTB中複製所有文本。 – Toby 2013-04-10 11:33:35