System.Windows.Forms.Clipboard.GetData(string)

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

20 Examples 7

1. Example

Project: storybrew
Source File: ClipboardHelper.cs
View license
public static object GetData(string format)
            => Misc.WithRetries(() => Clipboard.GetData(format), 500, false);

2. Example

View license
public NbtClipboardData CopyFromClipboard ()
        {
            NbtClipboardDataWin clip = Clipboard.GetData(typeof(NbtClipboardDataWin).FullName) as NbtClipboardDataWin;
            if (clip == null)
                return null;

            TagNode node = clip.Node;
            if (node == null)
                return null;

            return new NbtClipboardData(clip.Name, node);
        }

3. Example

Project: KeeThief
Source File: ClipboardUtil.cs
View license
public static byte[] GetData(string strFormat)
		{
			try
			{
				object o = Clipboard.GetData(strFormat);
				if(o == null) return null;

				byte[] pb = (o as byte[]);
				if(pb != null) return pb;

				MemoryStream ms = (o as MemoryStream);
				if(ms != null) return ms.ToArray();
			}
			catch(Exception) { Debug.Assert(false); }

			return null;
		}

4. Example

Project: noterium
Source File: TextClipper.cs
View license
private string GetActiveWindowsTextSelection()
        {
            // Obtain the handle of the active window.
            //IntPtr handle = GetForegroundWindow();
            //SendCtrlC(handle);

            if (Clipboard.ContainsData(DataFormats.Html))
            {
                var html = (string) Clipboard.GetData(DataFormats.Html);

                var output = ClipboardHtmlHelper.ParseString(html);

                if (!string.IsNullOrWhiteSpace(output.Source))
                {
                    return string.Format("<a href=\"{0}\">{0}</a><br /><br />{1}", output.Source, output.Html);
                }
                return output.Html;
            }

            return Clipboard.GetText();
        }

5. Example

View license
private void PasteClipboard()
		{
			try
			{
				if (Clipboard.ContainsData("ws.model.columncollection"))
				{
					var document = new XmlDocument();
					document.LoadXml((string)Clipboard.GetData("ws.model.columncollection"));
					foreach (XmlNode node in document.DocumentElement.SelectNodes("column"))
					{
						this.PasteColumn(node);
					}
					this.OnItemChanged(this, new System.EventArgs());
				}
				else if (Clipboard.ContainsData("ws.model.column"))
				{
					var document = new XmlDocument();
					document.LoadXml((string)Clipboard.GetData("ws.model.column"));
					this.PasteColumn(document.DocumentElement);
					this.OnItemChanged(this, new System.EventArgs());
				}

			}
			catch (Exception ex)
			{
				throw;
			}
		}

6. Example

View license
private void PasteMenuClick(object sender, System.EventArgs e)
		{
			try
			{
				if (Clipboard.ContainsData("ws.model.storedprocedurecolumn"))
				{
					var document = new XmlDocument();
					document.LoadXml((string)Clipboard.GetData("ws.model.storedprocedurecolumn"));

					var newItem = ((CustomStoredProcedureColumnCollection)this.Object).Add();
					var id = newItem.Id;
					newItem.XmlLoad(document.DocumentElement);
					newItem.SetId(id);
					newItem.SetKey(Guid.NewGuid().ToString());
					newItem.Name = "[" + newItem.Name + "]";
					this.OnItemChanged(this, new System.EventArgs());
				}
			}
			catch (Exception ex)
			{
				throw;
			}
		}

7. Example

Project: ecsharp
Source File: DiagramControl.cs
View license
[Command(null, "Paste")]
		public bool Paste(bool run = true)
		{
			if (Clipboard.ContainsData("DiagramDocument"))
			{
				if (run)
				{
					var buf = Clipboard.GetData("DiagramDocument") as byte[];
					if (buf != null)
						PasteAndSelect(new MemoryStream(buf), VectorT.Zero);
				}
				return true;
			}
			else if (Clipboard.ContainsText())
			{
				if (run)
				{
					var text = Clipboard.GetText();

					DoOrUndo act = null;
					if (_focusShape != null && (act = _focusShape.AppendTextAction(text)) != null)
						_doc.UndoStack.Do(act, true);
					else
					{
						var textBox = new TextBox(new BoundingBox<Coord>(0, 0, 300, 200))
						{
							Text = text,
							TextJustify = LLTextShape.JustifyMiddleCenter,
							BoxType = BoxType.Borderless,
							Style = BoxStyle
						};
						_doc.AddShape(textBox);
					}
				}
				return true;
			}
			return false;
		}

8. Example

Project: ReClass.NET
Source File: ReClassClipboard.cs
View license
public static Tuple<List<ClassNode>, List<BaseNode>> Paste(ReClassNetProject templateProject, ILogger logger)
		{
			Contract.Requires(templateProject != null);
			Contract.Requires(logger != null);
			Contract.Ensures(Contract.Result<Tuple<List<ClassNode>, List<BaseNode>>>() != null);

			var classes = new List<ClassNode>();
			var nodes = new List<BaseNode>();

			if (ContainsNodes)
			{
				if (Clipboard.GetData(ClipboardFormat) is byte[] data)
				{
					using (var ms = new MemoryStream(data))
					{
						var result = ReClassNetFile.ReadNodes(ms, templateProject, logger);
						classes.AddRange(result.Item1);
						nodes.AddRange(result.Item2);
					}
				}
			}

			return Tuple.Create(classes, nodes);
		}

9. Example

View license
private void PasteMenuClick(object sender, System.EventArgs e)
		{
			try
			{
				if (Clipboard.Con/n ..... /n //View Source file for more details /n }

10. Example

View license
private void PasteClipboard()
		{
			try
			{
				var customStoredProcedureCollection = (CustomStoredProcedureCollection)this.Object;
				if (Clipboard.ContainsData("ws.model.storedprocedurecollection"))
				{
					var document = new XmlDocument();
					document.LoadXml((string)Clipboard.GetData("ws.model.storedprocedurecollection"));
					foreach (XmlNode node in document.DocumentElement.SelectNodes("z"))
					{
						var tableNode = node.SelectSingleNode("storedprocedure");
						var columnListNode = node.SelectSingleNode("columnList");
						var parameterListNode = node.SelectSingleNode("parameterList");
						this.PasteTable(customStoredProcedureCollection, tableNode, columnListNode, parameterListNode);
					}
					this.OnItemChanged(this, new System.EventArgs());
				}
				else if (Clipboard.ContainsData("ws.model.storedprocedure"))
				{
					var document = new XmlDocument();
					document.LoadXml((string)Clipboard.GetData("ws.model.storedprocedure"));
					this.PasteTable(customStoredProcedureCollection,
						document.DocumentElement.SelectSingleNode("storedprocedure"),
						document.DocumentElement.SelectSingleNode("columnList"),
						document.DocumentElement.SelectSingleNode("parameterList"));
					this.OnItemChanged(this, new System.EventArgs());
				}

			}
			catch (Exception ex)
			{
				throw;
			}
		}

11. Example

View license
private void PasteClipboard()
		{
			try
			{
				var customViewCollection = (CustomViewCollection)this.Object;
				if (Clipboard.ContainsData("ws.model.viewcollection"))
				{
					var document = new XmlDocument();
					document.LoadXml((string)Clipboard.GetData("ws.model.viewcollection"));
					foreach (XmlNode node in document.DocumentElement.SelectNodes("z"))
					{
						var viewNode = node.SelectSingleNode("view");
						var columnListNode = node.SelectSingleNode("columnList");
						this.PasteTable(customViewCollection, viewNode, columnListNode);
					}
					this.OnItemChanged(this, new System.EventArgs());
				}
				else if (Clipboard.ContainsData("ws.model.view"))
				{
					var document = new XmlDocument();
					document.LoadXml((string)Clipboard.GetData("ws.model.view"));
					this.PasteTable(customViewCollection,
						document.DocumentElement.SelectSingleNode("view"),
						document.DocumentElement.SelectSingleNode("columnList"));
					this.OnItemChanged(this, new System.EventArgs());
				}

			}
			catch (Exception ex)
			{
				throw;
			}
		}

12. Example

View license
private void PasteClipboard()
		{
			try
			{
				var tableCollection = (TableCollection)this.Object;
				if (Clipboard.ContainsData("ws.model.tablecollection"))
				{
					var document = new XmlDocument();
					document.LoadXml((string)Clipboard.GetData("ws.model.tablecollection"));
					foreach (XmlNode node in document.DocumentElement.SelectNodes("z"))
					{
						var tableNode = node.SelectSingleNode("table");
						var columnListNode = node.SelectSingleNode("columnList");
						this.PasteTable(tableCollection, tableNode, columnListNode);
					}
					this.OnItemChanged(this, new System.EventArgs());
				}
				else if (Clipboard.ContainsData("ws.model.table"))
				{
					var document = new XmlDocument();
					document.LoadXml((string)Clipboard.GetData("ws.model.table"));
					this.PasteTable(tableCollection,
						document.DocumentElement.SelectSingleNode("table"),
						document.DocumentElement.SelectSingleNode("columnList"));
					this.OnItemChanged(this, new System.EventArgs());
				}

			}
			catch (Exception ex)
			{
				throw;
			}
		}

13. Example

Project: Dithering
Source File: ClipboardHelpers.cs
View license
public static Bitmap GetImage()
    {
      Bitmap result;

      // http://csharphelper.com/blog/2014/09/paste-a-png-format-image-with-a-transparent-background-from-the-clipboard-in-c/

      result = null;

      try
      {
        if (Clipboard.ContainsData(PngFormat))
        {
          object data;

          data = Clipboard.GetData(PngFormat);

          if (data != null)
          {
            Stream stream;

            stream = data as MemoryStream;

            if (stream == null)
            {
              byte[] buffer;

              buffer = data as byte[];

              if (buffer != null)
              {
                stream = new MemoryStream(buffer);
              }
            }

            if (stream != null)
            {
              result = Image.FromStream(stream).Copy();

              stream.Dispose();
            }
          }
        }

        if (result == null)
        {
          result = (Bitmap)Clipboard.GetImage();
        }
      }
      catch (Exception ex)
      {
        MessageBox.Show(string.Format("Failed to obtain image. {0}", ex.GetBaseException().Message), "Paste Image", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }

      return result;
    }

14. Example

Project: scada
Source File: FrmTable.cs
View license
public void CellPaste()
        {
            DataGridViewCell cell = dataGridView.CurrentCell;
    /n ..... /n //View Source file for more details /n }

15. Example

Project: ImageGlass
Source File: frmMain.cs
View license
private void mnuMainOpenImageData_Click(object sender, EventArgs e)
        {
            //Is there/n ..... /n //View Source file for more details /n }

16. Example

Project: noterium
Source File: ClipboardHelper.cs
View license
public static Image GetImageFromClipboard()
        {
            var dataObject = Clipboard.GetDataObject();
            if (dataObject == null)
                return null;

            if (dataObject.GetDataPresent(DataFormats.Dib))
            {
                var dib = ((MemoryStream) Clipboard.GetData(DataFormats.Dib)).ToArray();
                var width = BitConverter.ToInt32(dib, 4);
                var height = BitConverter.ToInt32(dib, 8);
                var bpp = BitConverter.ToInt16(dib, 14);
                if (bpp == 32)
                {
                    var gch = GCHandle.Alloc(dib, GCHandleType.Pinned);
                    Bitmap bmp = null;
                    try
                    {
                        var ptr = new IntPtr((long) gch.AddrOfPinnedObject() + 40);
                        bmp = new Bitmap(width, height, width*4, PixelFormat.Format32bppArgb, ptr);

                        var newBmp = new Bitmap(bmp);
                        newBmp.RotateFlip(RotateFlipType.Rotate180FlipX);
                        return newBmp;
                    }
                    finally
                    {
                        gch.Free();
                        bmp?.Dispose();
                    }
                }
            }

            return Clipboard.ContainsImage() ? Clipboard.GetImage() : null;
        }

17. Example

Project: HaSuite
Source File: InputHandler.cs
View license
private void parentBoard_ShortcutKeyPressed(Board selectedBoard, bool ctrl, bool shift, bool alt, Ke/n ..... /n //View Source file for more details /n }

18. 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;
			}
		}

19. 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 }

20. Example

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