System.Windows.Forms.DataObject.SetData(string, object)

Here are the examples of the csharp api class System.Windows.Forms.DataObject.SetData(string, object) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

41 Examples 7

1. Example

Project: KeeThief
Source File: ClipboardContents.cs
View license
private void SetDataPriv()
		{
			if(m_strText != null)
				ClipboardUtil.Copy(m_strText, false, false, null, null, IntPtr.Zero);
			else if(m_vContents != null)
			{
				DataObject dObj = new DataObject();
				foreach(KeyValuePair<string, object> kvp in m_vContents)
					dObj.SetData(kvp.Key, kvp.Value);

				ClipboardUtil.Clear();
				Clipboard.SetDataObject(dObj);
			}
		}

2. Example

View license
public static IDataObject CreateFrom(IHTMLElement element, string editorId)
        {
            // create a new new data object
            DataObject dataObject = new DataObject();

            //add internal format
            if (element != null)
            {
                dataObject.SetData(INTERNAL_SMART_CONTENT_DATAFORMAT, element.id);
                dataObject.SetData(INSTANCE_ID_DATAFORMAT, editorId);
            }

            // return the data object
            return dataObject;
        }

3. Example

Project: HTML-Renderer
Source File: ClipboardHelper.cs
View license
public static void CopyToClipboard(string plainText)
        {
            var dataObject = new DataObject();
            dataObject.SetData(DataFormats.Text, plainText);
            dataObject.SetData(DataFormats.UnicodeText, plainText);
            Clipboard.SetDataObject(dataObject, true);
        }

4. Example

Project: P8Coder
Source File: FastColoredTextBox.cs
View license
protected virtual void OnCreateClipboardData(DataObject data)
        {
            var exp = new ExportToHTML();
            exp.UseBr = false;
            exp.UseNbsp = false;
            exp.UseStyleTag = true;
            string html = "<pre>" + exp.GetHtml(Selection.Clone()) + "</pre>";

            data.SetData(DataFormats.UnicodeText, true, Selection.Text);
            data.SetData(DataFormats.Html, PrepareHtmlForClipboard(html));
            data.SetData(DataFormats.Rtf, new ExportToRTF().GetRtf(Selection.Clone()));
        }

5. Example

Project: dash-core
Source File: FastColoredTextBox.cs
View license
protected virtual void OnCreateClipboardData(DataObject data)
        {
            var exp = new ExportToHTML();
            exp.UseBr = false;
            exp.UseNbsp = false;
            exp.UseStyleTag = true;
            string html = "<pre>" + exp.GetHtml(Selection.Clone()) + "</pre>";

            data.SetData(DataFormats.UnicodeText, true, Selection.Text);
            data.SetData(DataFormats.Html, PrepareHtmlForClipboard(html));
            data.SetData(DataFormats.Rtf, new ExportToRTF().GetRtf(Selection.Clone()));
        }

6. Example

View license
private void Copy()
        {
            //	Instantiate the data object.
            DataObject dataObject = new DataObject();

            //	Set a Text format with the selected entries string.
            dataObject.SetData(DataFormats.Text, SelectedEntriesString());

            //	Finally, set the data object on the clipboard.
            Clipboard.SetDataObject(dataObject, true);
        }

7. Example

Project: ynoteclassic
Source File: FastColoredTextBox.cs
View license
protected virtual void OnCreateClipboardData(DataObject data)
		{
			var exp = new ExportToHTML();
			exp.UseBr = false;
			exp.UseNbsp = false;
			exp.UseStyleTag = true;
			string html = "<pre>" + exp.GetHtml(Selection.Clone()) + "</pre>";

			data.SetData(DataFormats.UnicodeText, true, Selection.Text);
			data.SetData(DataFormats.Html, PrepareHtmlForClipboard(html));
			data.SetData(DataFormats.Rtf, new ExportToRTF().GetRtf(Selection.Clone()));
		}

8. Example

Project: tesvsnip
Source File: MainView.cs
View license
internal static void SetClipboardData(object value)
        {
            if (Settings.Default.UseWindowsClipboard)
            {
                var cloneable = value as ICloneable;
                if (cloneable != null)
                {
                    var ido = new DataObject();
                    var srFormat = value.GetType().FullName;
                    ido.SetData(srFormat, cloneable.Clone());
                    ido.SetData("TESVSnip", srFormat);
                    System.Windows.Forms.Clipboard.Clear();
                    System.Windows.Forms.Clipboard.SetDataObject(ido, true);
                }
            }
            else
            {
                s_clipboard = value;
            }
        }

9. Example

Project: falloutsnip
Source File: MainView.Selection.cs
View license
internal static void SetClipboardData(object value)
        {
            if (Settings.Default.UseWindowsClipboard)
            {
                var cloneable = value as ICloneable;
                if (cloneable != null)
                {
                    var ido = new DataObject();
                    var srFormat = value.GetType().FullName;
                    ido.SetData(srFormat, cloneable.Clone());
                    ido.SetData("FalloutSnip", srFormat);
                    System.Windows.Forms.Clipboard.Clear();
                    System.Windows.Forms.Clipboard.SetDataObject(ido, true);
                }
            }
            else
            {
                s_clipboard = value;
            }
        }

10. Example

Project: logwizard
Source File: clipboard_util.cs
View license
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;
        }

11. Example

Project: WzComparerR2
Source File: ImageDataObject.cs
View license
public override object GetData(string format, bool autoConvert)
        {
            if (format == DataFormats.Bitmap
                || format == typeof(Bitmap).FullName)
            {
                PrepareImageFile();
                base.SetData(DataFormats.Bitmap, this.FileName);
            }
            else if (format == DataFormats.FileDrop
                || format == "FileName"
                || format == "FileNameW")
            {
                PrepareImageFile();
                base.SetData(DataFormats.FileDrop, new string[] { this.FileName });
            }
            else if (format == QQ_RichEdit_Format)
            {
                PrepareImageFile();
                byte[] buffer = Encoding.Default.GetBytes(GetQQRichFormatString());
                this.SetData(QQ_RichEdit_Format, new MemoryStream(buffer));
            }
            else if (format == QQ_Unicode_RichEdit_Format)
            {
                PrepareImageFile();
                byte[] buffer = Encoding.Unicode.GetBytes(GetQQRichFormatString());
                this.SetData(QQ_Unicode_RichEdit_Format, new MemoryStream(buffer));
            }

            return base.GetData(format, autoConvert);
        }

12. Example

Project: HTML-Renderer
Source File: ClipboardHelper.cs
View license
public static DataObject CreateDataObject(string html, string plainText)
        {
            html = html ?? String.Empty;
            var htmlFragment = GetHtmlDataString(html);
            
            // re-encode the string so it will work correctly (fixed in CLR 4.0)
            if (Environment.Version.Major < 4 && html.Length != Encoding.UTF8.GetByteCount(html))
                htmlFragment = Encoding.Default.GetString(Encoding.UTF8.GetBytes(htmlFragment));

            var dataObject = new DataObject();
            dataObject.SetData(DataFormats.Html, htmlFragment);
            dataObject.SetData(DataFormats.Text, plainText);
            dataObject.SetData(DataFormats.UnicodeText, plainText);
            return dataObject;
        }

13. Example

Project: Zydeo
Source File: ClipboardHelper.cs
View license
public static DataObject CreateDataObject(string html, string plainText)
        {
            html = html ?? String.Empty;
            var htmlFragment = GetHtmlDataString(html);

            // re-encode the string so it will work correctly (fixed in CLR 4.0)
            if (Environment.Version.Major < 4 && html.Length != Encoding.UTF8.GetByteCount(html))
                htmlFragment = Encoding.Default.GetString(Encoding.UTF8.GetBytes(htmlFragment));

            var dataObject = new DataObject();
            dataObject.SetData(DataFormats.Html, htmlFragment);
            dataObject.SetData(DataFormats.Text, plainText);
            dataObject.SetData(DataFormats.UnicodeText, plainText);
            return dataObject;
        }

14. Example

Project: duality
Source File: ConversionData.cs
View license
object IDataObject.GetData(string format, bool autoConvert)
		{
			bool isCached = 
				this.dataCache.GetDataPresent(format, autoConvert) || 
				this.dataCache.GetWrappedDataPresent(format);

			if (!isCached)
			{
				object obj;
				if (this.data.GetDataPresent(format, autoConvert))
					obj = this.data.GetData(format, autoConvert);
				else if (this.data.GetWrappedDataPresent(format))
					obj = this.data.GetWrappedData(format);
				else
					obj = null;

				if (obj != null)
					this.dataCache.SetData(format, obj);
			}

			return this.dataCache.GetData(format, autoConvert);
		}

15. Example

Project: superputty
Source File: ImageListPopup.cs
View license
protected override void OnMouseMove(MouseEventArgs mea)
        {
            // Update the popup only if the image selection has changed
            if (ClientRectangle.Contains(new Point(mea.X, mea.Y)))
            {
                if (EnableDragDrop && _bIsMouseDown)
                {
                    int nImage = _nCoordY * _nColumns + _nCoordX;
                    DataObject data = new DataObject();
                    data.SetData(DataFormats.Text, nImage.ToString());
                    data.SetData(DataFormats.Bitmap, _imageList.Images[nImage]);
                    DragDropEffects dde = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Move);
                    _bIsMouseDown = false;
                }

                if ((mea.X / _nItemWidth != _nCoordX) || (mea.Y / _nItemHeight != _nCoordY))
                {
                    _nCoordX = mea.X / _nItemWidth;
                    _nCoordY = mea.Y / _nItemHeight;
                    Invalidate();
                }
            }
            else
            {
                _nCoordX = -1;
                _nCoordY = -1;
                Invalidate();
            }
            base.OnMouseMove(mea);
        }

16. Example

Project: ATF
Source File: CircuitEditingContext.cs
View license
public virtual object Copy()
        {
            // copy selected text in the selected annotation?/n ..... /n //View Source file for more details /n }

17. Example

View license
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));
				
				SafeSetClipboard(dataObject);
				return true;
			} else {
				return false;
			}
		}

18. Example

Project: duality
Source File: ProjectFolderView.cs
View license
protected void ClipboardCutNodes(IEnumerable<TreeNodeAdv> nodes)
		{
			DataObject data = new DataObject();
			this.AppendNodesToData(data, nodes);
			Clipboard.SetDataObject(data, true);

			byte[] moveEffect = new byte[] {2, 0, 0, 0};
			MemoryStream dropEffect = new MemoryStream();
			dropEffect.Write(moveEffect, 0, moveEffect.Length);

			data.SetData("Preferred DropEffect", dropEffect);

			Clipboard.Clear();
			Clipboard.SetDataObject(data);
		}

19. Example

Project: tesvsnip
Source File: HexBox.cs
View license
public void Copy()
        {
            if (!CanCopy()) return;

            // put bytes into buffer
            var buffer = new byte[_selectionLength];
            int id = -1;
            for (long i = _bytePos; i < _bytePos + _selectionLength; i++)
            {
                id++;

                buffer[id] = _byteProvider.ReadByte(i);
            }

            var da = new DataObject();

            // set string buffer clipbard data
            string sBuffer = Encoding.Instance.GetString(buffer, 0, buffer.Length);
            da.SetData(typeof (string), sBuffer);

            //set memorystream (BinaryData) clipboard data
            var ms = new MemoryStream(buffer, 0, buffer.Length, false, true);
            da.SetData("BinaryData", ms);

            Clipboard.SetDataObject(da, true);
            UpdateCaret();
            ScrollByteIntoView();
            Invalidate();
        }

20. Example

Project: falloutsnip
Source File: HexBox.cs
View license
public void Copy()
        {
            if (!CanCopy()) return;

            // put bytes into buffer
            var buffer = new byte[_selectionLength];
            int id = -1;
            for (long i = _bytePos; i < _bytePos + _selectionLength; i++)
            {
                id++;

                buffer[id] = _byteProvider.ReadByte(i);
            }

            var da = new DataObject();

            // set string buffer clipbard data
            string sBuffer = Encoding.Instance.GetString(buffer, 0, buffer.Length);
            da.SetData(typeof (string), sBuffer);

            //set memorystream (BinaryData) clipboard data
            var ms = new MemoryStream(buffer, 0, buffer.Length, false, true);
            da.SetData("BinaryData", ms);

            Clipboard.SetDataObject(da, true);
            UpdateCaret();
            ScrollByteIntoView();
            Invalidate();
        }

21. Example

Project: ImageGlass
Source File: frmMain.cs
View license
private void CutFile()
        {
            try
            {
                if (GlobalSetting.IsImageError || !File.Exists(GlobalSetting.ImageList.GetFileName(GlobalSetting.CurrentIndex)))
                {
                    return;
                }
            }
            catch { return; }

            GlobalSetting.StringClipboard = new StringCollection();
            GlobalSetting.StringClipboard.Add(GlobalSetting.ImageList.GetFileName(GlobalSetting.CurrentIndex));

            byte[] moveEffect = new byte[] { 2, 0, 0, 0 };
            MemoryStream dropEffect = new MemoryStream();
            dropEffect.Write(moveEffect, 0, moveEffect.Length);

            DataObject data = new DataObject();
            data.SetFileDropList(GlobalSetting.StringClipboard);
            data.SetData("Preferred DropEffect", dropEffect);

            Clipboard.Clear();
            Clipboard.SetDataObject(data, true);

            DisplayTextMessage(
                string.Format(GlobalSetting.LangPack.Items["frmMain._CutFileText"],
                GlobalSetting.StringClipboard.Count), 1000);
        }

22. Example

Project: ImageGlass
Source File: frmMain.cs
View license
private void CutMultiFiles()
        {
            try
            {
                if (GlobalSetting.IsImageError || !File.Exists(GlobalSetting.ImageList.GetFileName(GlobalSetting.CurrentIndex)))
                {
                    return;
                }
            }
            catch { return; }

            //get filename
            string filename = GlobalSetting.ImageList.GetFileName(GlobalSetting.CurrentIndex);

            //exit if duplicated filename
            if (GlobalSetting.StringClipboard.IndexOf(filename) != -1)
            {
                return;
            }

            //add filename to clipboard
            GlobalSetting.StringClipboard.Add(filename);

            byte[] moveEffect = new byte[] { 2, 0, 0, 0 };
            MemoryStream dropEffect = new MemoryStream();
            dropEffect.Write(moveEffect, 0, moveEffect.Length);

            DataObject data = new DataObject();
            data.SetFileDropList(GlobalSetting.StringClipboard);
            data.SetData("Preferred DropEffect", dropEffect);

            Clipboard.Clear();
            Clipboard.SetDataObject(data, true);

            DisplayTextMessage(
                string.Format(GlobalSetting.LangPack.Items["frmMain._CutFileText"],
                GlobalSetting.StringClipboard.Count), 1000);
        }

23. Example

Project: AzureKeyVaultExplorer
Source File: Utils.cs
View license
public static void ClipboardSetHyperlink(string link, string name)
        {
            // HTML format which works fine with any Office product
            const string html = @"Version:0.9
                StartHTML:<<<<<<<1
                EndHTML:<<<<<<<2
                StartFragment:<<<<<<<3
                EndFragment:<<<<<<<4
                SourceURL: {0}
                <html>
                <body>
                <!--StartFragment-->
                <a href='{0}'>{1}</a>
                <!--EndFragment-->
                </body>
                </html>";
            var dataObj = new DataObject("Preferred DropEffect", DragDropEffects.Move); // "Cut" file to clipboard
            dataObj.SetData(DataFormats.Text, link);
            dataObj.SetData(DataFormats.UnicodeText, link);
            // Add HTML format and .URL as a file
            dataObj.SetData(DataFormats.Html, string.Format(html, link, name));
            var tempPath = Path.Combine(Path.GetTempPath(), name + ContentType.KeyVaultLink.ToExtension());
            File.WriteAllText(tempPath, $"[InternetShortcut]\r\nURL={link}\r\nIconIndex=47\r\nIconFile=%SystemRoot%\\system32\\SHELL32.dll");
            var sc = new StringCollection();
            sc.Add(tempPath);
            dataObj.SetFileDropList(sc);
            Clipboard.SetDataObject(dataObj, true);
        }

24. Example

Project: fomm
Source File: HexBox.cs
View license
public void Copy()
    {
      if (!CanCopy())
      {
        return;
      }

      // put bytes into buffer
      var buffer = new byte[_selectionLength];
      var id = -1;
      for (var i = _bytePos; i < _bytePos + _selectionLength; i++)
      {
        id++;

        buffer[id] = _byteProvider.ReadByte(i);
      }

      var da = new DataObject();

      // set string buffer clipbard data
      var sBuffer = Encoding.ASCII.GetString(buffer, 0, buffer.Length);
      da.SetData(typeof (string), sBuffer);

      //set memorystream (BinaryData) clipboard data
      var ms = new MemoryStream(buffer, 0, buffer.Length, false, true);
      da.SetData("BinaryData", ms);

      Clipboard.SetDataObject(da, true);
      UpdateCaret();
      ScrollByteIntoView();
      Invalidate();
    }

25. Example

Project: Screna
Source File: Extensions.cs
View license
public static void WriteToClipboard(this Bitmap BMP, bool PreserveTransparency = true)
        {
            if (PreserveTransparency)
            {
                using (var pngStream = new MemoryStream())
                {
                    BMP.Save(pngStream, ImageFormat.Png);
                    var pngClipboardData = new DataObject("PNG", pngStream);

                    using (var whiteS = new Bitmap(BMP.Width, BMP.Height, PixelFormat.Format24bppRgb))
                    {
                        using (var graphics = Graphics.FromImage(whiteS))
                        {
                            graphics.Clear(Color.White);
                            graphics.DrawImage(BMP, 0, 0, BMP.Width, BMP.Height);
                        }

                        // Add fallback for applications that don't support PNG from clipboard (eg. Photoshop or Paint)
                        pngClipboardData.SetData(DataFormats.Bitmap, whiteS);

                        Clipboard.Clear();
                        Clipboard.SetDataObject(pngClipboardData, true);
                    }
                }
            }
            else Clipboard.SetImage(BMP);
        }

26. Example

Project: Captura
Source File: Extensions.cs
View license
public static void WriteToClipboard(this Bitmap BMP, bool PreserveTransparency = true)
        {
            if (PreserveTransparency)
            {
                using (var pngStream = new MemoryStream())
                {
                    BMP.Save(pngStream, ImageFormat.Png);
                    var pngClipboardData = new DataObject("PNG", pngStream);

                    using (var whiteS = new Bitmap(BMP.Width, BMP.Height, PixelFormat.Format24bppRgb))
                    {
                        using (var graphics = Graphics.FromImage(whiteS))
                        {
                            graphics.Clear(Color.White);
                            graphics.DrawImage(BMP, 0, 0, BMP.Width, BMP.Height);
                        }

                        // Add fallback for applications that don't support PNG from clipboard (eg. Photoshop or Paint)
                        pngClipboardData.SetData(DataFormats.Bitmap, whiteS);

                        Clipboard.Clear();
                        Clipboard.SetDataObject(pngClipboardData, true);
                    }
                }
            }
            else Clipboard.SetImage(BMP);
        }

27. Example

Project: NoteHighlight2016
Source File: HtmlFragment.cs
View license
public static void CopyToClipboard(string htmlFragment, string title, Uri sourceUrl)
        {
     /n ..... /n //View Source file for more details /n }

28. Example

Project: NSMB-Editor
Source File: HexBox.cs
View license
public void Copy()
		{
			if(!CanCopy()) return;

			// put bytes into buffer
            byte[] buffer = GetCopyData();

			DataObject da = new DataObject();

			// set string buffer clipbard data
			string sBuffer = System.Text.Encoding.ASCII.GetString(buffer, 0, buffer.Length);
			da.SetData(typeof(string), sBuffer);

			//set memorystream (BinaryData) clipboard data
			System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer, 0, buffer.Length, false, true);
			da.SetData("BinaryData", ms);

			Clipboard.SetDataObject(da, true);
			UpdateCaret();
			ScrollByteIntoView();
			Invalidate();

            OnCopied(EventArgs.Empty);
		}

29. Example

Project: NSMB-Editor
Source File: HexBox.cs
View license
public void CopyHex()
        {
            if (!CanCopy()) return;

            // put bytes into buffer
            byte[] buffer = GetCopyData();

            DataObject da = new DataObject();

            // set string buffer clipbard data
            string hexString = ConvertBytesToHex(buffer); ;
            da.SetData(typeof(string), hexString);

            //set memorystream (BinaryData) clipboard data
            System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer, 0, buffer.Length, false, true);
            da.SetData("BinaryData", ms);

            Clipboard.SetDataObject(da, true);
            UpdateCaret();
            ScrollByteIntoView();
            Invalidate();

            OnCopiedHex(EventArgs.Empty);
        }

30. Example

Project: NBTExplorer
Source File: HexBox.cs
View license
public void Copy()
		{
			if(!CanCopy()) return;

			// put bytes into buffer
            byte[] buffer = GetCopyData();

			DataObject da = new DataObject();

			// set string buffer clipbard data
			string sBuffer = System.Text.Encoding.ASCII.GetString(buffer, 0, buffer.Length);
			da.SetData(typeof(string), sBuffer);

			//set memorystream (BinaryData) clipboard data
			System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer, 0, buffer.Length, false, true);
			da.SetData("BinaryData", ms);

			Clipboard.SetDataObject(da, true);
			UpdateCaret();
			ScrollByteIntoView();
			Invalidate();

            OnCopied(EventArgs.Empty);
		}

31. Example

Project: NBTExplorer
Source File: HexBox.cs
View license
public void CopyHex()
        {
            if (!CanCopy()) return;

            // put bytes into buffer
            byte[] buffer = GetCopyData();

            DataObject da = new DataObject();

            // set string buffer clipbard data
            string hexString = ConvertBytesToHex(buffer); ;
            da.SetData(typeof(string), hexString);

            //set memorystream (BinaryData) clipboard data
            System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer, 0, buffer.Length, false, true);
            da.SetData("BinaryData", ms);

            Clipboard.SetDataObject(da, true);
            UpdateCaret();
            ScrollByteIntoView();
            Invalidate();

            OnCopiedHex(EventArgs.Empty);
        }

32. Example

Project: ME3Explorer
Source File: HexBox.cs
View license
public void CopyHex()
        {
            if (!CanCopy()) return;

            // put bytes into buffer
            byte[] buffer = GetCopyData();

            DataObject da = new DataObject();

            // set string buffer clipbard data
            string hexString = ConvertBytesToHex(buffer); ;
            da.SetData(typeof(string), hexString);

            //set memorystream (BinaryData) clipboard data
            System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer, 0, buffer.Length, false, true);
            da.SetData("BinaryData", ms);

            Clipboard.SetDataObject(da, true);
            UpdateCaret();
            ScrollByteIntoView();
            Invalidate();

            OnCopiedHex(EventArgs.Empty);
        }

33. Example

Project: Be.HexEditor
Source File: HexBox.cs
View license
public void Copy()
		{
			if (!CanCopy()) return;

			// put bytes into buffer
			byte[] buffer = GetCopyData();

			DataObject da = new DataObject();

			// set string buffer clipbard data
			string sBuffer = System.Text.Encoding.ASCII.GetString(buffer, 0, buffer.Length);
			da.SetData(typeof(string), sBuffer);

			//set memorystream (BinaryData) clipboard data
			System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer, 0, buffer.Length, false, true);
			da.SetData("BinaryData", ms);

			Clipboard.SetDataObject(da, true);
			UpdateCaret();
			ScrollByteIntoView();
			Invalidate();

			OnCopied(EventArgs.Empty);
		}

34. Example

Project: Be.HexEditor
Source File: HexBox.cs
View license
public void CopyHex()
		{
			if (!CanCopy()) return;

			// put bytes into buffer
			byte[] buffer = GetCopyData();

			DataObject da = new DataObject();

			// set string buffer clipbard data
			string hexString = ConvertBytesToHex(buffer); ;
			da.SetData(typeof(string), hexString);

			//set memorystream (BinaryData) clipboard data
			System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer, 0, buffer.Length, false, true);
			da.SetData("BinaryData", ms);

			Clipboard.SetDataObject(da, true);
			UpdateCaret();
			ScrollByteIntoView();
			Invalidate();

			OnCopiedHex(EventArgs.Empty);
		}

35. Example

Project: ecsharp
Source File: DiagramControl.cs
View license
[Command(null, "Copy")]
		public bool Copy(bool run = true)
		{
			if (_selectedShapes.Count == 0)
				return false;
			if (run)
			{
				var buf = SerializeSelected();
				var data = new DataObject();

				data.SetData("DiagramDocument", buf.ToArray());

				var sortedShapes = _selectedShapes.OrderBy(s =>
				{
					var c = s.BBox.Center();
					return c.Y + c.X / 10;
				});
				var text = StringExt.Join("\n\n", sortedShapes
					.Select(s => s.PlainText()).Where(t => !string.IsNullOrEmpty(t)));
				if (!string.IsNullOrEmpty(text))
					data.SetText(text);

				// Crazy Clipboard deletes data by default on app exit!
				// need 'true' parameter to prevent loss of data on exit
				Clipboard.SetDataObject(data, true);
			}
			return true;
		}

36. Example

Project: ME3Explorer
Source File: HexBox.cs
View license
public void Copy()
        {
            if (!CanCopy()) return;

            // put bytes into buffer
            byte[] buffer = GetCopyData();

            DataObject da = new DataObject();

            // set string buffer clipbard data
            string sBuffer = "";
            if (_keyInterpreter == _ki && buffer.Length < 2000)
            {
                for (int i = 0; i < buffer.Length; i++)
                {
                    sBuffer += buffer[i].ToString("x2");
                }
            }
            else
            {
                sBuffer = System.Text.Encoding.ASCII.GetString(buffer, 0, buffer.Length);
            }
            da.SetData(typeof(string), sBuffer);

            //set memorystream (BinaryData) clipboard data
            System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer, 0, buffer.Length, false, true);
            da.SetData("BinaryData", ms);

            Clipboard.SetDataObject(da, true);
            UpdateCaret();
            ScrollByteIntoView();
            Invalidate();

            OnCopied(EventArgs.Empty);
        }

37. Example

View license
public virtual void Copy()
        {
            Range selectionToRestore = null;
            if (Selection.IsEmpty)
            {
                selectionToRestore = Selection.Clone();
                Selection.Expand();
            }
            if (!Selection.IsEmpty)
            {
                var exp = new ExportToHTML();
                exp.UseBr = false;
                exp.UseNbsp = false;
                exp.UseStyleTag = true;
                string html = "<pre>" + exp.GetHtml(Selection.Clone()) + "</pre>";
                var data = new DataObject();
                data.SetData(DataFormats.UnicodeText, true, Selection.Text);
                data.SetData(DataFormats.Html, PrepareHtmlForClipboard(html));
                data.SetData(DataFormats.Rtf, new ExportToRTF().GetRtf(Selection.Clone()));
                //
                var thread = new Thread(() => SetClipboard(data));
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
                thread.Join();

                if (selectionToRestore != null)
                {
                    Selection = selectionToRestore;
                }
            }
        }

38. Example

Project: winforms
Source File: BitmaskEditorTemplate.cs
View license
public void OnKeyDown(KeyEventArgs e)
		{
			if (e.KeyCode == Keys.ControlKey)
				this.EmitInvalidate();

			if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Right || (e.KeyCode == Keys.Down && e.Control))
			{
				this.ShowDropDown();
				e.Handled = true;
			}
			else if (e.Control && e.KeyCode == Keys.C)
			{
				DataObject data = new DataObject();
				data.SetText(this.bitmaskStr);
				data.SetData(ClipboardDataFormat, this.bitmask);
				Clipboard.SetDataObject(data);
				e.Handled = true;
			}
			else if (e.Control && e.KeyCode == Keys.V)
			{
				bool success = false;
				ulong pasteValue = 0; 
				if (Clipboard.ContainsData(ClipboardDataFormat))
				{
					pasteValue = (ulong)Clipboard.GetData(ClipboardDataFormat);
					success = true;
				}
				else if (Clipboard.ContainsText())
				{
					string[] pasteObj = Clipboard.GetText().Split(new [] { ", " }, StringSplitOptions.RemoveEmptyEntries);
					foreach (string p in pasteObj)
					{
						if (p == null) continue;
						BitmaskItem item = this.dropdownItems.FirstOrDefault(obj => obj != null && p == obj.ToString());
						if (item != null)
						{
							pasteValue |= item.Value;
							success = true;
						}
					}
				}
				if (success)
				{
					this.bitmask = pasteValue;
					this.bitmaskStr = this.DefaultValueStringGenerator(this.bitmask);
					this.EmitInvalidate();
					this.EmitEdited(this.bitmask);
				}
				else
					System.Media.SystemSounds.Beep.Play();
				e.Handled = true;
			}
		}

39. Example

Project: winforms
Source File: ComboBoxEditorTemplate.cs
View license
public void OnKeyDown(KeyEventArgs e)
		{
			if (e.KeyCode == Keys.ControlKey)
				this.EmitInvalida/n ..... /n //View Source file for more details /n }

40. Example

View license
public void OnKeyDown(KeyEventArgs e)
		{
			if (e.KeyCode == Keys.ControlKey)
				this.EmitInvalida/n ..... /n //View Source file for more details /n }

41. Example

Project: aeroshot
Source File: Screenshot.cs
View license
internal static void CaptureWindow(ref ScreenshotTask data)
        {
            IntPtr start = Win/n ..... /n //View Source file for more details /n }