How can I enumerate the clipboard formats

时光总嘲笑我的痴心妄想 提交于 2019-12-10 17:55:01

问题


With WPF, I can get data in a given format from the clipboard:

object test = Clipboard.GetGata (format);

How can I enumerate the list of formats present in the clipboard?


回答1:


 List<String> dataFormats = typeof(DataFormats).GetFields(BindingFlags.Public | BindingFlags.Static)
                                .Select(f => f.Name)
                                .ToList();

this should give you all the Fields from DataFormats

List<String> dataFormatsInClipboard = 
             dataFormats.Where( df => Clipboard.ContainsData(df) )
             .ToList();

will give you just the ones that match the clipboard.




回答2:


Have a look at the IDataObject class.

IDataObject content = Clipboard.GetDataObject();
string [] formats = clipContent.GetFormats();


来源:https://stackoverflow.com/questions/5836801/how-can-i-enumerate-the-clipboard-formats

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!