C#实现剪切板功能
作者:鲁迅认识的那只猹 时间:2023-01-16 12:26:48
C#剪切板
Clipboard类
我们现在先来看一下官方文档的介绍
位于:System.Windows.Forms 命名空间下
Provides methods to place data on and retrieve data from the system Clipboard. This class cannot be inherited.
提供一些方法来存放数据和取回数据从系统的剪切板,这个类不能被实例化。
从官方的描述我们可以看出Clipboard是一个用来存放一些临时数据来用的...这句话是个废话,因为我们经常 复制站粘贴了。
Method
ContainsImage() 判断剪切板中是否包含图片数据
Note:
我们从系统中通过 Control+C 复制出来的图像文件实际上复制的不是图像文件本身而是图像文件的全路径。
private void btnContainsImage_Click(object sender, EventArgs e)
{
//将图片放置到剪切板中
Image img = Image.FromFile("file.png");
Clipboard.SetImage(img);
//判断剪切板中是否包含图片
bool flag = Clipboard.ContainsImage();
Console.WriteLine(flag);
}
ContainsText() 判断剪切板中是否包含文本数据
private void btnContains_Click(object sender, EventArgs e)
{
//判断剪切板中是否包含文本数据
bool flag = Clipboard.ContainsText();
Console.WriteLine(flag);
}
GetFileDropList() 获取剪切板中文件名的集合
private void btnGetPath_Click(object sender, EventArgs e)
{
//因为剪切板是可以复制多个文件的所有要遍历获取
StringCollection sc = Clipboard.GetFileDropList();
foreach (var item in sc)
{
Console.WriteLine(item.ToString());
}
}
/*输出结果:
C:\Users\IT\Desktop\drive.png
C:\Users\IT\Desktop\folder.png
C:\Users\IT\Desktop\file.png
*/
SetDataObject() 向剪切板中放置数据
private void btnSetData_Click(object sender, EventArgs e)
{
string data = "天王盖地虎!";
Clipboard.SetDataObject(data);
string text = Clipboard.GetText();
Console.WriteLine(text);
}
来源:http://www.cnblogs.com/slyfox/p/7115543.html
标签:C#,剪切板
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java模拟微信抢红包的实例代码
2021-12-08 19:51:21
C#获取指定年份第一个星期一具体日期的方法
2023-03-06 19:18:18
JAVA使用POI获取Excel的列数与行数
2021-10-03 12:53:37
mybatis拦截器与分页插件实例教程
2021-11-16 15:41:48
![](https://img.aspxhome.com/file/2023/7/91067_0s.jpg)
Java输入/输出流体系详解
2023-03-01 06:37:00
![](https://img.aspxhome.com/file/2023/9/65739_0s.png)
SpringBoot实现接口数据的加解密功能
2023-06-30 00:11:01
![](https://img.aspxhome.com/file/2023/8/63008_0s.png)
JDK8中新增的原子性操作类LongAdder详解
2023-06-19 22:02:58
![](https://img.aspxhome.com/file/2023/3/76303_0s.jpg)
详解Flutter网络图片本地缓存的实现
2023-08-18 19:44:43
Android中实现iOS中的毛玻璃效果
2023-01-27 01:44:14
![](https://img.aspxhome.com/file/2023/1/139571_0s.jpg)
深入浅析Java Object Serialization与 Hadoop 序列化
2023-07-30 17:02:16
C#实现进制转换
2021-11-22 11:52:13
java加载properties文件的六种方法总结
2023-09-20 05:24:54
![](https://img.aspxhome.com/file/2023/9/64809_0s.png)
C#多线程系列之任务基础(三)
2023-10-08 13:43:34
centos下GitLab+Jenkins持续集成环境搭建(安装jenkins)
2023-05-13 05:02:40
![](https://img.aspxhome.com/file/2023/2/90202_0s.png)
C#深拷贝方法探究及性能比较(多种深拷贝)
2022-08-30 18:17:02
![](https://img.aspxhome.com/file/2023/5/77235_0s.png)
Android基于Fresco实现圆角和圆形图片
2023-02-14 20:03:29
![](https://img.aspxhome.com/file/2023/6/138096_0s.jpg)
Java解码H264格式视频流中的图片
2023-11-24 23:58:24
mybatis-plus使用问题小结
2023-10-30 06:45:58
C# 对象持久化详解
2023-06-24 10:21:47
![](https://img.aspxhome.com/file/2023/7/83357_0s.png)
Android ListView与RecycleView的对比使用解析
2022-05-05 16:56:02
![](https://img.aspxhome.com/file/2023/8/104678_0s.png)