开发者

Include Font while pasting to Clipboard

开发者 https://www.devze.com 2023-02-19 14:16 出处:网络
I\'m trying to include the font \"KaiTi\" while setting text on the clipboard, so that wherever I paste the data, the \"KaiTi\" Font will be the font that the text is in, inevitably keeping all of the

I'm trying to include the font "KaiTi" while setting text on the clipboard, so that wherever I paste the data, the "KaiTi" Font will be the font that the text is in, inevitably keeping all of the data that I am pastin开发者_高级运维g to the clipboard formatted the way that I want it too.

This is what I tried, I know it's off, but I don't know what to do..

            TextBox texter = new TextBox();
            texter.Text = strToClips;
            texter.Font = new Font("KaiTi", 10);
            Clipboard.SetText(texter.Text);


Use a RichTextBox. It puts rich text on the clipboard that includes formatting. Use its Copy() method. Pasting back now also works automatically without any code.


The richtextbox displayed the formatting OK, but I couldn't get Copy() to bring the font across. In the end I selected the text then sent a Ctrl-C character to copy it, as follows:-

myrichtextbox.SelectAll();
myrichtextbox.Focus();
SendKeys.Send("^C");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号