本文整理汇总了C#中System.Windows.Forms.DataObject.GetFormats方法的典型用法代码示例。如果您正苦于以下问题:C# DataObject.GetFormats方法的具体用法?C# DataObject.GetFormats怎么用?C# DataObject.GetFormats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DataObject
的用法示例。
在下文中一共展示了DataObject.GetFormats方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestConvertible
public void TestConvertible ()
{
DataObject o = new DataObject ();
o.SetData (DataFormats.Text, false, "abc");
Assert.AreEqual (new string [] { DataFormats.Text }, o.GetFormats (), "#01");
Assert.AreEqual (new string [] { DataFormats.Text }, o.GetFormats (true), "#02");
Assert.AreEqual (new string [] { DataFormats.Text }, o.GetFormats (false), "#03");
o = new DataObject ();
o.SetData (DataFormats.Text, true, "abc");
Assert.AreEqual (new string [] { DataFormats.StringFormat, DataFormats.UnicodeText, DataFormats.Text }, o.GetFormats (), "#B1");
Assert.AreEqual (new string [] { DataFormats.StringFormat, DataFormats.UnicodeText, DataFormats.Text }, o.GetFormats (), "#B2");
Assert.AreEqual (new string [] { DataFormats.Text }, o.GetFormats (false), "#B3");
o = new DataObject ();
o.SetData (DataFormats.UnicodeText, true, "abc");
Assert.AreEqual (new string [] { DataFormats.StringFormat, DataFormats.UnicodeText, DataFormats.Text }, o.GetFormats (), "#C1");
Assert.AreEqual (new string [] { DataFormats.StringFormat, DataFormats.UnicodeText, DataFormats.Text }, o.GetFormats (), "#C2");
Assert.AreEqual (new string [] { DataFormats.UnicodeText }, o.GetFormats (false), "#C3");
o = new DataObject ();
o.SetData (DataFormats.UnicodeText, false, "abc");
Assert.AreEqual (new string [] { DataFormats.UnicodeText }, o.GetFormats (), "#D1");
Assert.AreEqual (new string [] { DataFormats.UnicodeText}, o.GetFormats (), "#D2");
Assert.AreEqual (new string [] { DataFormats.UnicodeText }, o.GetFormats (false), "#D3");
o = new DataObject ();
o.SetData (DataFormats.StringFormat, true, "abc");
Assert.AreEqual (new string [] { DataFormats.StringFormat, DataFormats.UnicodeText, DataFormats.Text }, o.GetFormats (), "#C1");
Assert.AreEqual (new string [] { DataFormats.StringFormat, DataFormats.UnicodeText, DataFormats.Text }, o.GetFormats (), "#C2");
Assert.AreEqual (new string [] { DataFormats.StringFormat }, o.GetFormats (false), "#C3");
o = new DataObject ();
o.SetData (DataFormats.StringFormat, false, "abc");
Assert.AreEqual (new string [] { DataFormats.StringFormat }, o.GetFormats (), "#D1");
Assert.AreEqual (new string [] { DataFormats.StringFormat }, o.GetFormats (), "#D2");
Assert.AreEqual (new string [] { DataFormats.StringFormat }, o.GetFormats (false), "#D3");
}
示例2: AddToClipboard
/// <summary>
/// Adds the specified data to the clipboard
/// </summary>
public static void AddToClipboard(params ClipboardData[] data)
{
Forms.IDataObject dataObject = new Forms.DataObject();
foreach (var clipboardData in data)
{
if (clipboardData.Data != null)
dataObject.SetData(Clipboard.FormatToString(clipboardData.Format), clipboardData.Data);
}
if (dataObject.GetFormats().Length > 1)
{
Forms.Clipboard.SetDataObject(dataObject, copy: true);
}
}
示例3: AddToClipboard
/// <summary>
/// Adds the specified data to the clipboard
/// </summary>
/// <exception cref="ArgumentNullException">Thrown if <param name="nameof(data)"/> is null.</exception>
public static void AddToClipboard(params ClipboardData[] data)
{
if (data == null) throw new ArgumentNullException(nameof(data));
Forms.IDataObject dataObject = new Forms.DataObject();
foreach (var clipboardData in data)
{
if (clipboardData.Data != null)
dataObject.SetData(GetDataObjectFormatString(clipboardData.Format), clipboardData.Data);
}
if (dataObject.GetFormats().Length > 1)
{
Forms.Clipboard.SetDataObject(dataObject, copy: true);
}
}
示例4: IsFormatValid
private static bool IsFormatValid(DataObject data)
{
return IsFormatValid(data.GetFormats());
}
示例5: ProcessesTreeViewDragDrop
private void ProcessesTreeViewDragDrop(object sender, DragEventArgs e)
{
var data = new DataObject(new TreeNodeAdv(new Node()));
if (!e.Data.GetDataPresent(data.GetFormats()[0])) return;
var draggedTreeNode = (TreeNodeAdv)e.Data.GetData(data.GetFormats()[0]);
var draggedNode = (DeviareNode)draggedTreeNode.Tag;
var targetTreeNode = _processesTreeView.DropPosition.Node;
var targetNode = (DeviareNode)targetTreeNode.Tag;
var processCollector = new Collector();
targetNode.Accept(processCollector);
var hookCollector = new Collector();
draggedNode.Accept(hookCollector);
_presenter.ReplicateHooks(processCollector.CollectedProcesses, hookCollector.CollectedHooks);
}
示例6: SetDragDropMode
private static void SetDragDropMode(DragEventArgs e)
{
var data = new DataObject(new TreeNodeAdv(new Node()));
if (e.Data.GetDataPresent(data.GetFormats()[0]))
{
e.Effect = DragDropEffects.Link;
return;
}
e.Effect = DragDropEffects.None;
}
示例7: GetCellClipboardContent
//-------------------------------------------------------------------------------------
/// <summary>
/// опирует в clipboard текущую ¤чейку. ”дал¤ет формат html представлени¤.
/// </summary>
/// <returns></returns>
public DataObject GetCellClipboardContent()
{
DataObject obj = new DataObject(CurrentCell.FormattedValue);
DataObject newObj = new DataObject();
//this.Sele
string[] types = obj.GetFormats();
foreach(String type in types)
{
if(type != DataFormats.Html)
newObj.SetData(type, obj.GetData(type));
}
return newObj;
}
示例8: Main
public static void Main ()
{
PrintFormatInfo(DataFormats.GetFormat(DataFormats.Bitmap));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.CommaSeparatedValue));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.Dib));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.Dif));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.EnhancedMetafile));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.FileDrop));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.Html));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.Locale));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.MetafilePict));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.OemText));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.Palette));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.PenData));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.Riff));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.Rtf));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.Serializable));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.StringFormat));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.SymbolicLink));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.Text));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.Tiff));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.UnicodeText));
PrintFormatInfo(DataFormats.GetFormat(DataFormats.WaveAudio));
// Add our own format
PrintFormatInfo(DataFormats.GetFormat("Birthday"));
// Test some basic stuff
DataObject dobj;
Control c;
string rtf;
c = new Control();
rtf = "\\r\\t\\f string";
// Load the data object
dobj = new DataObject(DataFormats.Text, "I am text");
dobj.SetData(c.GetType(), c);
dobj.SetData(DataFormats.Rtf, rtf);
PrintFormats("GetFormats(): ", dobj.GetFormats()); // Count should be 5
PrintFormats("GetFormats(true): ", dobj.GetFormats(true)); // Count should be 5
PrintFormats("GetFormats(false): ", dobj.GetFormats(false)); // Count should be 3
Console.WriteLine("GetDataPresent(typeof(string)): {0}", dobj.GetDataPresent(typeof(string))); // We expect true
Console.WriteLine("GetDataPresent(DataFormats.Text): {0}", dobj.GetDataPresent(DataFormats.Text)); // We expect true
Console.WriteLine("GetDataPresent(DataFormats.WaveAudio): {0}", dobj.GetDataPresent(DataFormats.WaveAudio)); // We expect false
Console.WriteLine("GetData(DataFormats.Rtf): {0}", dobj.GetData(DataFormats.Rtf)); // We expect "\r\t\f string"
clipboard clip = new clipboard ();
PrintClipboardContents();
IDataObject data;
data = Clipboard.GetDataObject();
if (data != null && data.GetDataPresent(DataFormats.Bitmap)) {
image = (Image)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);
}
Bitmap i = new Bitmap("test.bmp");
string s = "bummerä";
Clipboard.SetDataObject(s);
Application.Run (clip);
}
示例9: GetClipboardData
private void GetClipboardData()
{
//
// Data on the clipboard uses the
// IDataObject interface
//
IDataObject dataObject = new DataObject();
try
{
dataObject = Clipboard.GetDataObject();
}
catch (Exception ex)
{
MessageBox.Show("Clip2Web Error: " + ex.ToString());
return;
}
var formats = dataObject.GetFormats();
if(formats.Contains(INTERESTING_FORMAT) || dataObject.GetDataPresent(DataFormats.Bitmap))
{
m_imageData = (System.Drawing.Bitmap)dataObject.GetData(DataFormats.Bitmap);
m_trayIcon.ShowBalloonTip(1000, "Clip Saved!", "Click to copy path", ToolTipIcon.Info);
}
}