本文整理汇总了C#中System.Windows.DataObject.GetFormats方法的典型用法代码示例。如果您正苦于以下问题:C# DataObject.GetFormats方法的具体用法?C# DataObject.GetFormats怎么用?C# DataObject.GetFormats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DataObject
的用法示例。
在下文中一共展示了DataObject.GetFormats方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyToClipboard
private void CopyToClipboard(object sender, RoutedEventArgs args)
{
var dataObject = new DataObject();
// Copy data from RichTextBox/File content into DataObject
if ((bool) rbCopyDataFromRichTextBox.IsChecked)
{
CopyDataFromRichTextBox(dataObject);
}
else
{
CopyDataFromFile(dataObject);
}
// Copy DataObject on the system Clipboard
if (dataObject.GetFormats().Length > 0)
{
if ((bool) cbFlushOnCopy.IsChecked)
{
// Copy data to the system clipboard with flush
Clipboard.SetDataObject(dataObject, true /*copy*/);
}
else
{
// Copy data to the system clipboard without flush
Clipboard.SetDataObject(dataObject, false /*copy*/);
}
}
// Dump the copied data contents on the information panel
DumpAllClipboardContentsInternal();
}
示例2: Defaults
public void Defaults ()
{
DataObject dobj = new DataObject ();
Assert.Throws<SecurityException> (() => dobj.GetFormats (), "GetFormats ()");
Assert.Throws<SecurityException> (() => dobj.GetFormats (true), "GetFormats (true)");
Assert.Throws<SecurityException> (() => dobj.GetFormats (false), "GetFormats (false)");
Assert.Throws<SecurityException> (() => dobj.GetData (DataFormats.FileDrop), "GetData (string)");
Assert.Throws<SecurityException> (() => dobj.GetData (DataFormats.FileDrop, true), "GetData (string,true)");
Assert.Throws<SecurityException> (() => dobj.GetData (DataFormats.FileDrop, false), "GetData (string,false)");
Assert.Throws<SecurityException> (() => dobj.GetData (typeof(string)), "GetData (Type)");
Assert.Throws<SecurityException> (() => dobj.GetDataPresent (DataFormats.FileDrop), "GetDataPresent (string)");
Assert.Throws<SecurityException> (() => dobj.GetDataPresent (DataFormats.FileDrop, true), "GetDataPresent (string,true)");
Assert.Throws<SecurityException> (() => dobj.GetDataPresent (DataFormats.FileDrop, false), "GetDataPresent (string,false)");
Assert.Throws<SecurityException> (() => dobj.GetDataPresent (typeof (string)), "GetDataPresent (Type)");
Assert.Throws<SecurityException> (() => dobj.SetData (DataFormats.FileDrop), "SetData (string)");
Assert.Throws<SecurityException> (() => dobj.SetData (DataFormats.FileDrop, true), "SetData (string,true)");
Assert.Throws<SecurityException> (() => dobj.SetData (DataFormats.FileDrop, false), "SetData (string,false)");
Assert.Throws<SecurityException> (() => dobj.SetData (typeof (string)), "SetData (Type)");
}
示例3: TextSelectionToDataObject
private void TextSelectionToDataObject(object sender, RoutedEventArgs e)
{
// Create a new data object using one of the overloaded constructors. This particular
// overload accepts a string specifying the data format (provided by the DataFormats class),
// and an Object (in this case a string) that represents the data to be stored in the data object.
var dataObject = new DataObject(DataFormats.Text, sourceTextBox.SelectedText);
dataObjectInfoTextBox.Clear();
// Get and display the native data formats (filtering out auto-convertable data formats).
dataObjectInfoTextBox.Text = "\nNative data formats present:\n";
foreach (var format in dataObject.GetFormats(false /*autoconvert*/))
dataObjectInfoTextBox.Text += format + "\n";
// Display the data in the data object.
dataObjectInfoTextBox.Text += "\nData contents:\n";
dataObjectInfoTextBox.Text += dataObject.GetData(DataFormats.Text, false /*autoconvert*/).ToString();
}
示例4: FormatEnumerator
//------------------------------------------------------
//
// Constructors
//
//------------------------------------------------------
#region Constructors
// Creates a new enumerator instance.
internal FormatEnumerator(DataObject dataObject)
{
FORMATETC temp;
string[] formats;
formats = dataObject.GetFormats();
_formats = new FORMATETC[formats == null ? 0 : formats.Length];
if (formats != null)
{
for (int i = 0; i < formats.Length; i++)
{
string format;
format = formats[i];
temp = new FORMATETC();
temp.cfFormat = (short)DataFormats.GetDataFormat(format).Id;
temp.dwAspect = DVASPECT.DVASPECT_CONTENT;
temp.ptd = IntPtr.Zero;
temp.lindex = -1;
if (IsFormatEqual(format, DataFormats.Bitmap))
{
temp.tymed = TYMED.TYMED_GDI;
}
else if (IsFormatEqual(format, DataFormats.EnhancedMetafile))
{
temp.tymed = TYMED.TYMED_ENHMF;
}
else
{
temp.tymed = TYMED.TYMED_HGLOBAL;
}
_formats[i] = temp;
}
}
}