clipboardwrapper.cs
来自「SharpDevelop2.0.0 c#开发免费工具」· CS 代码 · 共 74 行
CS
74 行
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision: 1117 $</version>
// </file>
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace ICSharpCode.Core
{
/// <summary>
/// Helper class to access the clipboard without worrying about ExternalExceptions
/// </summary>
public static class ClipboardWrapper
{
public static bool ContainsText {
get {
try {
LoggingService.Debug("ContainsText called");
return Clipboard.ContainsText();
} catch (ExternalException) {
return false;
}
}
}
public static string GetText()
{
// retry 2 times should be enough for read access
try {
return Clipboard.GetText();
} catch (ExternalException) {
return Clipboard.GetText();
}
}
public static void SetText(string text)
{
DataObject data = new DataObject();
data.SetData(DataFormats.UnicodeText, true, text);
SetDataObject(data);
}
public static IDataObject GetDataObject()
{
// retry 2 times should be enough for read access
try {
return Clipboard.GetDataObject();
} catch (ExternalException) {
try {
return Clipboard.GetDataObject();
} catch (ExternalException) {
return new DataObject();
}
}
}
public static void SetDataObject(object data)
{
try {
Clipboard.SetDataObject(data, true, 10, 50);
} catch (ExternalException) {
Application.DoEvents();
try {
Clipboard.SetDataObject(data, true, 10, 50);
} catch (ExternalException) { }
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?