简体   繁体   English

复制粘贴剪贴板 RTF C#

[英]Copy&Paste Clipboard RTF C#

i try to copy a table with Pictures from a WPF Richtextbox to a Forms Richtextbox above clipboard.我尝试将带有图片的表格从 WPF Richtextbox 复制到剪贴板上方的 Forms Richtextbox。 Both are only code-generated.两者都只是代码生成的。 Not a big Thing, but it will not work.不是什么大事,但它不会起作用。

  tmp_rtf_wpf.SelectAll();
                       
  tmp_rtf_wpf.Copy();
//But if i add a Messagebox here, it works
  tmp_rtf_forms.Paste();
//or if i add a Messagebox here, it works too

So i think, the Copy() is not finished.所以我认为, Copy() 还没有完成。 (if Messagebox is shown the Picture with Table is in the Clipboard, and without Messagebox - if i later read the Clipboard the Picture it is inside too, if i use only text and no Picture, it is the same) (如果显示消息框,则带有表格的图片在剪贴板中,而没有消息框 - 如果我稍后阅读剪贴板中的图片,它也在里面,如果我只使用文本而不使用图片,它是相同的)

ok, finally i use this as a "workaround":好的,最后我将其用作“解决方法”:

TextRange tr = new TextRange(tmp_rtf_wpf.Document.ContentStart,
                                tmp_rtf_wpf.Document.ContentEnd);
                        MemoryStream ms = new MemoryStream();
                        tr.Save(ms, DataFormats.Rtf);
                        string wpfrtf_tmp = ASCIIEncoding.Default.GetString(ms.ToArray());

                        Clipboard.SetText(wpfrtf_tmp, TextDataFormat.Rtf);
 tmp_rtf_forms.Paste();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM