本文整理汇总了C#中System.Windows.Forms.DataObject类的典型用法代码示例。如果您正苦于以下问题:C# DataObject类的具体用法?C# DataObject怎么用?C# DataObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataObject类属于System.Windows.Forms命名空间,在下文中一共展示了DataObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyButtonClick
private void CopyButtonClick(object sender, EventArgs e)
{
var dateTime = DateTime.Parse(DateTextBox.Text, DateTextBox.Culture, DateTimeStyles.AssumeLocal);
var timeSpan = dateTime.ToUniversalTime() - Epoch;
var dataObject = new DataObject();
var messagePlain = string.Format(
"[{0:hh:mm:ss}] {1}: {2}",
dateTime,
AuthorFullNameTextBox.Text,
MessageTextBox.Text);
var messageXml = string.Format(
"<quote author=\"{0}\" timestamp=\"{1}\">{2}</quote>",
AuthorTextBox.Text,
timeSpan.TotalSeconds,
MessageTextBox.Text);
dataObject.SetData("System.String", messagePlain);
dataObject.SetData("UnicodeText", messagePlain);
dataObject.SetData("Text", messagePlain);
dataObject.SetData("SkypeMessageFragment", new MemoryStream(Encoding.UTF8.GetBytes(messageXml)));
dataObject.SetData("Locale", new MemoryStream(BitConverter.GetBytes(CultureInfo.CurrentCulture.LCID)));
dataObject.SetData("OEMText", messagePlain);
Clipboard.SetDataObject(dataObject, true);
}
示例2: CloneClipboard
private IDataObject CloneClipboard(IDataObject obj)
{
if (obj == null)
return null;
string[] formats = obj.GetFormats();
if (formats.Length == 0)
return null;
IDataObject newObj = new DataObject();
foreach (string format in formats)
{
if (format.Contains("EnhancedMetafile")) //Ignore this. Cannot be processed in .NET
continue;
object o = obj.GetData(format);
if (o != null)
{
newObj.SetData(o);
}
}
return newObj;
}
示例3: label2_MouseDown
private void label2_MouseDown(object sender, MouseEventArgs e)
{
// Start drag-and-drop if left mouse goes down over this label
if (e.Button == MouseButtons.Left)
{
// Crete a new data object
DataObject data = new DataObject();
// Get the TextBox text
string dragString = this.textBox1.Text;
// If the TextBox text was empty then use a default string
if (string.IsNullOrEmpty(dragString))
dragString = "Empty string";
// Set the DataOject's data to a new SampleCsDragData object which
// can be serialized. If you use an object that does not support the
// serialize interface then you will NOT be able to drag and drop the
// item onto a different session of Rhino.
data.SetData(new SampleCsDragData(dragString));
// Start drag-and-drop
this.DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Move);
}
}
示例4: RtfTextTest
public void RtfTextTest ()
{
string rtf_text = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial;}}{\*\generator Mono RichTextBox;}\pard\f0\fs16 hola\par}";
string plain_text = "hola";
Clipboard.SetText (rtf_text, TextDataFormat.Rtf);
Assert.AreEqual (false, Clipboard.ContainsText (TextDataFormat.Text), "#A1");
Assert.AreEqual (false, Clipboard.ContainsText (TextDataFormat.UnicodeText), "#A2");
Assert.AreEqual (true, Clipboard.ContainsText (TextDataFormat.Rtf), "#A3");
Assert.AreEqual (rtf_text, Clipboard.GetText (TextDataFormat.Rtf), "#A4");
// Now use a IDataObject, so we can have more than one format at the time
DataObject data = new DataObject ();
data.SetData (DataFormats.Rtf, rtf_text);
data.SetData (DataFormats.UnicodeText, plain_text);
Clipboard.SetDataObject (data);
Assert.AreEqual (true, Clipboard.ContainsText (TextDataFormat.Text), "#B1");
Assert.AreEqual (true, Clipboard.ContainsText (TextDataFormat.UnicodeText), "#B2");
Assert.AreEqual (true, Clipboard.ContainsText (TextDataFormat.Rtf), "#B3");
Assert.AreEqual (rtf_text, Clipboard.GetText (TextDataFormat.Rtf), "#B4");
Assert.AreEqual (plain_text, Clipboard.GetText (), "#B5");
Clipboard.Clear ();
}
示例5: GetDataObjectFromText
protected override IDataObject GetDataObjectFromText(string text)
{
DataObject obj2 = new DataObject();
obj2.SetData(DataFormats.Text, text);
obj2.SetData(DataFormats.Html, text);
return obj2;
}
示例6: OnDropOnLayerListCtrl
/// <summary>
/// This method is called when the drag and drop operation is completed and
/// the item being dragged was dropped on the Rhino layer list control.
/// </summary>
public override bool OnDropOnLayerListCtrl(IWin32Window layerListCtrl, int layerIndex, DataObject data, DragDropEffects dropEffect, Point point)
{
SampleCsDragData dragData = GetSampleCsDragData(data);
if (null == dragData)
return false;
if (layerIndex < 0)
{
MessageBox.Show(
RhUtil.RhinoApp().MainWnd(),
"String \"" + dragData.DragString + "\" Dropped on layer list control, not on a layer",
"SampleCsDragDrop",
MessageBoxButtons.OK,
MessageBoxIcon.Information
);
}
else
{
MRhinoDoc doc = RhUtil.RhinoApp().ActiveDoc();
if (null != doc && layerIndex < doc.m_layer_table.LayerCount())
{
MessageBox.Show(
RhUtil.RhinoApp().MainWnd(),
"String \"" + dragData.DragString + "\" Dropped on layer \"" + doc.m_layer_table[layerIndex].m_name + "\"",
"SampleCsDragDrop",
MessageBoxButtons.OK,
MessageBoxIcon.Information
);
}
}
return true;
}
示例7: copyToClipboard
public static void copyToClipboard(List<Frame> frames)
{
if (frames.Count == 0)
{
return;
}
DataObject data = new DataObject();
data.SetData(frames.ToArray());
if (frames.Count == 1)
{
// Not necessary, but Microsoft recommends that we should
// place data on the clipboard in as many formats possible.
data.SetData(frames[0]);
}
StringBuilder sb = new StringBuilder();
foreach (Frame frame in frames)
{
sb.AppendLine(frame.getTabSeparatedString());
}
data.SetText(sb.ToString());
Clipboard.SetDataObject(data, true);
}
示例8: DeserializeFromData
protected override void DeserializeFromData(DataObject data)
{
ConvertOperation convert = new ConvertOperation(data, ConvertOperation.Operation.Convert);
if (convert.CanPerform(this.editedCmpType))
{
var refQuery = convert.Perform(this.editedCmpType);
if (refQuery != null)
{
Component[] refArray = refQuery.Cast<Component>().ToArray();
this.component = (refArray != null && refArray.Length > 0) ? refArray[0] : null;
this.PerformSetValue();
this.PerformGetValue();
this.OnEditingFinished(FinishReason.LeapValue);
}
}
else if (convert.CanPerform(typeof(GameObject)))
{
GameObject obj = convert.Perform<GameObject>().FirstOrDefault();
Component cmp = obj != null ? obj.GetComponent(this.editedCmpType) : null;
if (cmp != null)
{
this.component = cmp;
this.PerformSetValue();
this.PerformGetValue();
this.OnEditingFinished(FinishReason.LeapValue);
}
}
}
示例9: treeView1_ItemDrag
private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
{
// gx2. jsx, jsc reflector
// ?
// http://support.microsoft.com/kb/307968
// we can drag it into scite
// DragDrop.DoDragDrop returns only after the complete drag-drop process is finished,
// http://w3facility.org/question/dodragdrop-freezes-winforms-app-sometimes/
// https://msdn.microsoft.com/en-us/library/ms649011(VS.85).aspx
// http://www.codeproject.com/Articles/17266/Drag-and-Drop-Items-in-a-WPF-ListView
Console.WriteLine("treeView1_ItemDrag"); ;
// http://stackoverflow.com/questions/1772102/c-sharp-drag-and-drop-from-my-custom-app-to-notepad
var x = new DataObject(
"treeView1_ItemDrag " + new { e.Item }
);
// like props/ reg keys/ version nodes
x.SetData("text/nodes/0", "hello");
x.SetData("text/nodes/1", "world");
// https://msdn.microsoft.com/en-us/library/system.windows.forms.control.dodragdrop(v=vs.110).aspx
//this.DoDragDrop("treeView1_ItemDrag " + new { e.Item }, DragDropEffects.Copy);
treeView1.DoDragDrop(x, DragDropEffects.Copy);
// https://code.google.com/p/chromium/issues/detail?id=31037
// https://searchcode.com/codesearch/view/32985148/
}
示例10: Copy
public void Copy()
{
IDataObject clips = new DataObject();
clips.SetData(DataFormats.Bitmap, this.opened_image.get_bitmap());
clips.SetData(DataFormats.Text, this.opened_image.get_file_name());
Clipboard.SetDataObject(clips, true);
}
示例11: Copy
/// <summary>
/// Copy selected text into Clipboard
/// </summary>
public static void Copy(FastColoredTextBox textbox)
{
if (textbox.Selection.IsEmpty)
{
textbox.Selection.Expand();
}
if (!textbox.Selection.IsEmpty)
{
var exp = new ExportToHTML();
exp.UseBr = false;
exp.UseNbsp = false;
exp.UseStyleTag = true;
string html = "<pre>" + exp.GetHtml(textbox.Selection.Clone()) + "</pre>";
var data = new DataObject();
data.SetData(DataFormats.UnicodeText, true, textbox.Selection.Text);
data.SetData(DataFormats.Html, PrepareHtmlForClipboard(html));
data.SetData(DataFormats.Rtf, new ExportToRTF().GetRtf(textbox.Selection.Clone()));
//
var thread = new Thread(() => SetClipboard(data));
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
}
}
示例12: OnActivateTool
/// <summary>
/// Called when the tool is activated.
/// </summary>
protected override void OnActivateTool()
{
if(Selection.SelectedItems.Count == 0)
return;
try
{
//Clear the Anchors otherwise subsequent Copy operations will raise an exception due to the fact that the Anchors class is a static helper class
Anchors.Clear();
//this will create a volatile collection of entities, they need to be unwrapped!
//I never managed to get things working by putting the serialized collection directly onto the Clipboad. Thanks to Leppie's suggestion it works by
//putting the Stream onto the Clipboard, which is weird but it works.
MemoryStream copy = Selection.SelectedItems.ToStream();
DataFormats.Format format = DataFormats.GetFormat(typeof(CopyTool).FullName);
IDataObject dataObject = new DataObject();
dataObject.SetData(format.Name, false, copy);
Clipboard.SetDataObject(dataObject, false);
}
catch (Exception exc)
{
throw new InconsistencyException("The Copy operation failed.", exc);
}
finally
{
DeactivateTool();
}
}
示例13: ToDataObject
public DataObject ToDataObject()
{
DataObject obj = new DataObject();
obj.SetData(DataFormats.Serializable, this);
obj.SetData(DataFormats.Text, Texte);
return obj;
}
示例14: Send
public void Send(string archiveFilename, CancellationToken cancellationToken, SimpleProgressCallback progressCallback = null)
{
// create drop effect memory stream
byte[] moveEffect = new byte[] { (byte) (performCut ? 2 : 5), 0, 0, 0 };
MemoryStream dropEffect = new MemoryStream();
dropEffect.Write(moveEffect, 0, moveEffect.Length);
// create file data object
DataObject data = new DataObject();
data.SetFileDropList(new StringCollection { archiveFilename });
data.SetData("Preferred DropEffect", dropEffect);
// create STA thread that'll work with Clipboard object
Thread copyStaThread = new Thread(() =>
{
Clipboard.Clear();
Clipboard.SetDataObject(data, true);
})
{
Name = "Clipboard copy thread"
};
copyStaThread.SetApartmentState(ApartmentState.STA);
// start the thread and wait for it to finish
copyStaThread.Start();
copyStaThread.Join();
}
示例15: copyToolStripMenuItem_Click
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
/*
SceneJS scene = (SceneJS)treeView1.Nodes[0].Tag;
if (scene != null)
{
object obj = scene.GetSelectedObject();
if( obj != null )
{
Clipboard.SetData("WebGLSceneObject", obj);
}
}
*/
Clipboard.Clear();
List<object> selected = new List<object>();
foreach (TreeNode n in treeView1.SelectedNodes)
{
selected.Add(n.Tag);
}
DataFormats.Format df = DataFormats.GetFormat(typeof(List<object>).FullName);
IDataObject dato = new DataObject();
dato.SetData(df.Name, false, selected);
Clipboard.SetDataObject(dato, false);
}