简体   繁体   English

以生成 Microsoft Teams 可以使用的格式的方式写入 C# 中的剪贴板

[英]Writing to the clipboard in C# in a way that generates formatting that Microsoft Teams can use

I've got an app that is meant to take a string, and write it into the clipboard at 30 pt font, Courier New.我有一个应用程序,旨在获取一个字符串,并将其以 30 pt 字体 Courier New 写入剪贴板。 The code below works great for word, outlook, basically anything that accepts RTF formatted text.下面的代码非常适用于单词 outlook,基本上是任何接受 RTF 格式文本的东西。 it isn't being seen as anything but plain text in Teams, unfortunately, which is the most common use case, and the most important by far.不幸的是,它在 Teams 中仅被视为纯文本,这是最常见的用例,也是迄今为止最重要的用例。 Does anyone have any insight on how to format it in a way that MS Teams will recognize?是否有人对如何以 MS Teams 识别的方式对其进行格式化有任何见解?

private void ExecuteCopy(String lap)
        {
            // Escape Special Characters for RTF
            StringBuilder rtf = new StringBuilder();
            StringBuilder html = new StringBuilder();
            html.Append("<p style = \"font - family:'Courier New'; font - size:30px\">");

            foreach (char c in lap)
            {
                rtf.Append(GetRtfEncoding(c));
                html.Append(c);
            }

            html.Append("</p>");

            // Add both RTF and plain Text into clipboard
            DataObject data = new DataObject();
            data.SetData(DataFormats.Text, lap);
            data.SetData(DataFormats.Rtf, @"{\rtf1\ansi\deff0 {\fonttbl {\f0 Courier New;}}\f0\fs60 " + rtf.ToString() + "}", true);
            data.SetData(DataFormats.Html, html, true);
            Clipboard.SetDataObject(data);
        }

Teams doesn't support rich HTML formatting like this, unfortunately.不幸的是,Teams 不支持像这样的丰富的 HTML 格式。 The best you'll get is some limited markdown support, but at least it's something.您将获得的最好的结果是一些有限的 markdown 支持,但至少它是一些东西。 See here for more: https://support.microsoft.com/en-ie/office/use-markdown-formatting-in-teams-4d10bd65-55e2-4b2d-a1f3-2bebdcd2c772 .请参阅此处了解更多信息: https://support.microsoft.com/en-ie/office/use-markdown-formatting-in-teams-4d10bd65-55e2-4b2d-a1f3-2bebdcd2c772

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

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