Zoop

alex_zoop

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 今天做一截图工具,发现能截图,但是点击Ctrl+V复制出来的根本不是图像,

查看代码,发现根本没有 将图片放入剪贴板,以便使用Ctrl+V复制的功能

 

搜了下,发现很简单,就一句话: Clipboard.SetImage(bmp);

 

 

Clipboard类的其他功能如下,能实现带格式文本复制或者单纯文本复制,

还能实现快捷键重置功能

 

 

using System;

using System.Collections.Specialized;

using System.Drawing;

using System.IO;

 

namespace System.Windows.Forms

{

    // 摘要:

    //     提供将数据置于系统剪贴板中以及从中检索数据的方法。无法继承此类。

    public sealed class Clipboard

    {

        // 摘要:

        //     从剪贴板中移除所有数据。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        public static void Clear();

        //

        // 摘要:

        //     指示在剪贴板中是否存在 System.Windows.Forms.DataFormats.WaveAudio 格式的数据。

        //

        // 返回结果:

        //     如果剪贴板中有音频数据,则为 true;否则为,false。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        public static bool ContainsAudio();

        //

        // 摘要:

        //     指示剪贴板中是否存在指定格式的数据,或可转换成此格式的数据。

        //

        // 参数:

        //   format:

        //     要查找的数据格式。请参见 System.Windows.Forms.DataFormats 以获取预定义的格式。

        //

        // 返回结果:

        //     如果在剪贴板中存在指定 format 或可以转换成该格式的数据,则为 true;否则为 false。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        public static bool ContainsData(string format);

        //

        // 摘要:

        //     指示剪贴板中是否存在 System.Windows.Forms.DataFormats.FileDrop 格式或可转换成此格式的数据。

        //

        // 返回结果:

        //     如果剪贴板中有文件放置列表,则为 true;否则为,false。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        public static bool ContainsFileDropList();

        //

        // 摘要:

        //     指示剪贴板中是否存在 System.Windows.Forms.DataFormats.Bitmap 格式或可转换成此格式的数据。

        //

        // 返回结果:

        //     如果剪贴板中存在图像数据,则为 true;否则为,false。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        public static bool ContainsImage();

        //

        // 摘要:

        //     指示剪贴板中是否存在 System.Windows.Forms.TextDataFormat.Text System.Windows.Forms.TextDataFormat.UnicodeText

        //     格式的数据(取决于操作系统)。

        //

        // 返回结果:

        //     如果剪贴板中存在文本数据,则为 true;否则为,false。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        public static bool ContainsText();

        //

        // 摘要:

        //     指示剪贴板中是否存在具有指定的 System.Windows.Forms.TextDataFormat 值所指示的格式的文本数据。

        //

        // 参数:

        //   format:

        //     System.Windows.Forms.TextDataFormat 值之一。

        //

        // 返回结果:

        //     如果剪贴板中存在格式值为指定 format 的文本数据,则为 true;否则为 false。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        //

        //   System.ComponentModel.InvalidEnumArgumentException:

        //     format 不是有效的 System.Windows.Forms.TextDataFormat 值。

        public static bool ContainsText(TextDataFormat format);

        //

        // 摘要:

        //     检索剪贴板上的音频流。

        //

        // 返回结果:

        //     包含音频数据的 System.IO.Stream;如果剪贴板不包含任何 System.Windows.Forms.DataFormats.WaveAudio

        //     格式的数据,则为 null。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        public static Stream GetAudioStream();

        //

        // 摘要:

        //     从剪贴板中检索指定格式的数据。

        //

        // 参数:

        //   format:

        //     要检索的数据的格式。请参见 System.Windows.Forms.DataFormats 以获取预定义的格式。

        //

        // 返回结果:

        //     表示剪贴板数据的 System.Object;如果剪贴板中包含的数据都不是指定 format,也无法转换为该格式,则为 null。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        public static object GetData(string format);

        //

        // 摘要:

        //     检索当前位于系统剪贴板中的数据。

        //

        // 返回结果:

        //     System.Windows.Forms.IDataObject,表示系统剪贴板中当前的数据;如果剪贴板中没有数据,则为 null。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     从剪贴板中检索不到数据。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下,且 System.Windows.Forms.Application.MessageLoop 属性值为

        //     true。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        public static IDataObject GetDataObject();

        //

        // 摘要:

        //     从剪贴板中检索文件名的集合。

        //

        // 返回结果:

        //     包含文件名的 System.Collections.Specialized.StringCollection;如果剪贴板中不包含任何格式为 System.Windows.Forms.DataFormats.FileDrop

        //     或可转换为该格式的数据,则为 null。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        public static StringCollection GetFileDropList();

        //

        // 摘要:

        //     检索剪贴板上的图像。

        //

        // 返回结果:

        //     表示剪贴板图像数据的 System.Drawing.Image;如果剪贴板中不包含任何 System.Windows.Forms.DataFormats.Bitmap

        //     格式或可转换成该格式的数据,则为 null。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        public static Image GetImage();

        //

        // 摘要:

        //     从剪贴板中检索 System.Windows.Forms.TextDataFormat.Text System.Windows.Forms.TextDataFormat.UnicodeText

        //     格式的文本数据(取决于操作系统)。

        //

        // 返回结果:

        //     剪贴板文本数据;如果剪贴板中不包含 System.Windows.Forms.TextDataFormat.Text System.Windows.Forms.TextDataFormat.UnicodeText

        //     格式的数据(取决于操作系统),则为 System.String.Empty。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        public static string GetText();

        //

        // 摘要:

        //     从剪贴板中检索由指定的 System.Windows.Forms.TextDataFormat 值表示的格式的文本数据。

        //

        // 参数:

        //   format:

        //     System.Windows.Forms.TextDataFormat 值之一。

        //

        // 返回结果:

        //     剪贴板文本数据;如果剪贴板中不包含指定格式的数据,则为 System.String.Empty

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        //

        //   System.ComponentModel.InvalidEnumArgumentException:

        //     format 不是有效的 System.Windows.Forms.TextDataFormat 值。

        public static string GetText(TextDataFormat format);

        //

        // 摘要:

        //     将 System.Byte 数组转换成 System.IO.Stream 之后,将该数组添加到格式为 System.Windows.Forms.DataFormats.WaveAudio

        //     的剪贴板中。

        //

        // 参数:

        //   audioBytes:

        //     包含音频数据的 System.Byte 数组。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        //

        //   System.ArgumentNullException:

        //     audioBytes 为 null。

        public static void SetAudio(byte[] audioBytes);

        //

        // 摘要:

        //     System.Windows.Forms.DataFormats.WaveAudio 格式的 System.IO.Stream 添加到剪贴板中。

        //

        // 参数:

        //   audioStream:

        //     包含音频数据的 System.IO.Stream。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        //

        //   System.ArgumentNullException:

        //     audioStream 为 null。

        public static void SetAudio(Stream audioStream);

        //

        // 摘要:

        //     将指定格式的数据添加到剪贴板中。

        //

        // 参数:

        //   format:

        //     要设置的数据格式。请参见 System.Windows.Forms.DataFormats 以获取预定义的格式。

        //

        //   data:

        //     表示要添加的数据的 System.Object。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        //

        //   System.ArgumentNullException:

        //     data 为 null。

        public static void SetData(string format, object data);

        //

        // 摘要:

        //     将非持久性数据置于系统剪贴板中。

        //

        // 参数:

        //   data:

        //     要置于剪贴板中的数据。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能将数据置于剪贴板中。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        //

        //   System.ArgumentNullException:

        //     data 的值为 null。

        public static void SetDataObject(object data);

        //

        // 摘要:

        //     将数据置于系统剪贴板中,并指定在退出应用程序后是否将数据保留在剪贴板中。

        //

        // 参数:

        //   data:

        //     要置于剪贴板中的数据。

        //

        //   copy:

        //     如果想在退出应用程序后将数据保留在剪贴板中,则为 true;否则为 false。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能将数据置于剪贴板中。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        //

        //   System.ArgumentNullException:

        //     data 的值为 null。

        public static void SetDataObject(object data, bool copy);

        //

        // 摘要:

        //     尝试指定的次数,以将数据置于系统剪贴板中,且两次尝试之间具有指定的延迟,可以选择在退出应用程序后将数据保留在剪贴板中。

        //

        // 参数:

        //   data:

        //     要置于剪贴板中的数据。

        //

        //   copy:

        //     如果想在退出应用程序后将数据保留在剪贴板中,则为 true;否则为 false。

        //

        //   retryTimes:

        //     尝试将数据置于剪贴板中的次数。

        //

        //   retryDelay:

        //     两次尝试之间暂停的毫秒数。

        //

        // 异常:

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        //

        //   System.ArgumentNullException:

        //     data 为 null。

        //

        //   System.ArgumentOutOfRangeException:

        //     retryTimes 小于零。- 或 -retryDelay 小于零。

        //

        //   System.Runtime.InteropServices.ExternalException:

        //     未能将数据置于剪贴板中。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        public static void SetDataObject(object data, bool copy, int retryTimes, int retryDelay);

        //

        // 摘要:

        //     System.Windows.Forms.DataFormats.FileDrop 格式的文件名集合添加到剪贴板中。

        //

        // 参数:

        //   filePaths:

        //     包含这些文件名的 System.Collections.Specialized.StringCollection

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        //

        //   System.ArgumentNullException:

        //     filePaths 为 null。

        //

        //   System.ArgumentException:

        //     filePaths 中不包含任何字符串。- 或 -在 filePaths 中至少有一个字符串为以下情况之一:为 System.String.Empty、仅包含空白、包含一个或多个

        //     System.IO.Path.InvalidPathChars 定义的无效字符、值为 null、包含冒号 (:)、或超出系统定义的最大长度。有关更多信息,请参见

        //     System.ArgumentException System.Exception.InnerException 属性。

        public static void SetFileDropList(StringCollection filePaths);

        //

        // 摘要:

        //     System.Windows.Forms.DataFormats.Bitmap 格式的 System.Drawing.Image 添加到剪贴板中。

        //

        // 参数:

        //   image:

        //     要添加到剪贴板中的 System.Drawing.Image。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        //

        //   System.ArgumentNullException:

        //     image 为 null。

        public static void SetImage(Image image);

        //

        // 摘要:

        //     System.Windows.Forms.TextDataFormat.Text 或 System.Windows.Forms.TextDataFormat.UnicodeText

        //     格式的文本数据添加到剪贴板中(取决于操作系统)。

        //

        // 参数:

        //   text:

        //     要添加到剪贴板中的文本。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        //

        //   System.ArgumentNullException:

        //     text 为 null 或 System.String.Empty。

        public static void SetText(string text);

        //

        // 摘要:

        //     将文本数据添加到剪贴板中,该数据的格式由指定的 System.Windows.Forms.TextDataFormat 值指示。

        //

        // 参数:

        //   text:

        //     要添加到剪贴板中的文本。

        //

        //   format:

        //     System.Windows.Forms.TextDataFormat 值之一。

        //

        // 异常:

        //   System.Runtime.InteropServices.ExternalException:

        //     未能清空剪贴板。这种情况通常发生在剪贴板正在被其他进程使用的时候。

        //

        //   System.Threading.ThreadStateException:

        //     当前线程未处于单线程单元 (STA) 模式下。请将 System.STAThreadAttribute 添加到应用程序的 Main 方法中。

        //

        //   System.ArgumentNullException:

        //     text 为 null 或 System.String.Empty。

        //

        //   System.ComponentModel.InvalidEnumArgumentException:

        //     format 不是有效的 System.Windows.Forms.TextDataFormat 值。

        public static void SetText(string text, TextDataFormat format);

    }

}

 

posted on 2011-08-25 15:28  zoop89850  阅读(800)  评论(0编辑  收藏  举报