【问题标题】:Is there a way to get the information on the current clipboard in C#?有没有办法在 C# 中获取当前剪贴板的信息?
【发布时间】:2021-10-13 00:22:00
【问题描述】:

我想在运行程序或应用程序之前设置的 Windows 剪贴板上获取信息,但我找不到方法。有没有办法在 C# 或 C++ 中获取当前剪贴板的信息?

【问题讨论】:

  • 欢迎来到stackoverflow。请阅读How to ask。值得注意的是,到目前为止,您做了哪些研究?你有什么尝试?
  • 是的,当然有。
  • Cmon....Clipboard Class

标签: c# c++ clipboard


【解决方案1】:

在c#中你可以使用Clipboard类:Clipboard

您可以通过以下方式检查是否有数据并进行检索:

bool IsHTMLDataOnClipboard = Clipboard.ContainsData(DataFormats.Html);

// If there is HTML data on the clipboard, retrieve it.
string htmlData;
if(IsHTMLDataOnClipboard)
{
    htmlData = Clipboard.GetText(TextDataFormat.Html);
}

【讨论】:

  • 我已经编辑了你的答案。我们知道文档中的链接不太可能丢失/失效,但请尽量避免仅提供链接的答案。
  • 你是对的,没想到这一点。谢谢!
  • 我从外面复制了一个字符串并尝试了string str = Clipboard.GetText(TextDataFormat.Text);string str = Clipboard.GetText();,但它们都不起作用;他们返回 NullReferenceException。我想知道我错过了什么。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-02-17
  • 2018-05-15
  • 2015-05-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多