C#获取剪切(粘贴)板的内容(图⽚、⽂字)Clipboard类、 Clipboard.GetDataObject() 、iData.GetDataPresent()…
DataFormats类型:
Bitmap 指定 Microsoft Windows 位图数据格式。
CommaSeparatedValue 指定以逗号分隔的值 (CSV) 数据格式。
Dib 指定 device-independent bitmap (DIB) 数据格式。
Dif 指定 Windows 数据交换格式 (DIF) 数据格式。
EnhancedMetafile 指定 Windows 增强型图元⽂件格式。
FileDrop 指定 Windows ⽂件放置格式。
Html 指定 HTML 数据格式。
Locale 指定 Windows 区域设置(区域性)数据格式。
MetafilePicture 指定 Windows 图元⽂件图⽚数据格式。
OemText 指定标准 Windows OEM ⽂本数据格式。
Palette 指定 Windows 调⾊板数据格式。
PenData 指定 Windows 钢笔数据格式。
Riff 指定 Resource Interchange File Format (RIFF) ⾳频数据格式。
Rtf 指定 Rich Text Format (RTF) 数据格式。
Serializable 指定封装任何类型的可序列化数据对象的数据格式。
StringFormat 指定 common language runtime (CLR) 字符串类数据格式。
SymbolicLink 指定 Windows 符号链接数据格式。
Text 指定 ANSI ⽂本数据格式。
Tiff 指定 Tagged Image File Format (TIFF) 数据格式。
UnicodeText 指定 Unicode ⽂本数据格式。
WaveAudio 指定波形⾳频数据格式。
unicode文件格式
Xaml 指定 Extensible Application Markup Language (XAML) 数据格式。
XamlPackage 指定 Extensible Application Markup Language (XAML) 包数据格式。
获取图⽚:
IDataObject iData = Clipboard.GetDataObject();
if(iData.GetDataPresent(DataFormats.MetafilePict))
{
var img = Clipboard.GetImage();
picBox.Tag = Guid.NewGuid();
picBox.Image = img;
}
else if(iData.GetDataPresent(DataFormats.FileDrop))
{
var files = Clipboard.GetFileDropList();
if(files.Count ==0){return;}
picBox.Tag = Guid.NewGuid();
picBox.Image = Image.FromFile(files[0]);
}
else if(iData.GetDataPresent(DataFormats.Text))
{
var path =(String)iData.GetData(DataFormats.Text);
var chars = Path.GetInvalidPathChars();
if(path.IndexOfAny(chars)>=0){
<("路径中包含⾮法字符!");
return;
}
if(System.IO.File.Exists(path))
{
var name = Path.GetFileNameWithoutExtension(path);
var extension = path.Substring(path.LastIndexOf("."));
string imgType =".png|.jpg|.jpeg";
if(imgType.Contains(extension.ToLower()))
{
picBox.Image = Image.FromFile(path);
picBox.Tag = Guid.NewGuid();
IsChanged =true;
}
else{
<("格式错误!");
}
}
else{
<("⽂件不存在!");
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。