/// <summary> /// Tries to get a typed clipboard format as a stream from the current clipboard. Returns false /// if the format does not exist, or fails for another reason. /// </summary> public virtual bool TryGetFormatStream(ClipboardFormat format, out Stream stream) { if (TryGetFormatObject(format.Id, new BytesDataConverter(), out var bytes)) { if (bytes != null) { stream = new MemoryStream(bytes); return(true); } } stream = default; return(false); }
/// <summary> /// Returns a list of all the formats currently stored in the current clipboard object. /// </summary> public virtual IEnumerable <ClipboardFormat> GetPresentFormats() { ThrowIfDisposed(); uint next = NativeMethods.EnumClipboardFormats(0); while (next != 0) { yield return(ClipboardFormat.GetFormatById(next)); next = NativeMethods.EnumClipboardFormats(next); } // If there are no more clipboard formats to enumerate, the return value is zero. // In this case, the GetLastError function returns the value ERROR_SUCCESS. var err = Marshal.GetLastWin32Error(); if (err != 0) { Marshal.ThrowExceptionForHR(err); } }
/// <summary> /// Set clipboard format to the current clipboard. This will clear the clipboard /// if this is the first call to "Set" since the clipboard handle was opened. /// </summary> public virtual void SetFormat(ClipboardFormat format, Stream stream) { var bytes = StructUtil.ReadBytes(stream); SetFormatObject(format.Id, bytes, new BytesDataConverter()); }
/// <summary> /// Set a clipboard format to the current clipboard. This will clear the clipboard /// if this is the first call to "Set" since the clipboard handle was opened. /// </summary> public virtual void SetFormat(ClipboardFormat format, byte[] bytes) { SetFormatObject(format.Id, bytes, new BytesDataConverter()); }
/// <summary> /// Set clipboard format to the current clipboard. This will clear the clipboard /// if this is the first call to "Set" since the clipboard handle was opened. /// </summary> public virtual void SetFormat <T>(ClipboardFormat <T> format, T obj) { SetFormatObject(format.Id, obj, format.TypeObjectReader); }
/// <summary> /// Retrieves a typed clipboard format as a stream from the current clipboard. Throws exception if /// the format is not currently on the clipboard. /// </summary> public virtual Stream GetFormatStream(ClipboardFormat format) { return(new MemoryStream(GetFormatBytes(format))); }
/// <summary> /// Retrieves a typed clipboard format as bytes from the current clipboard. Throws exception if /// the format is not currently on the clipboard. /// </summary> public virtual byte[] GetFormatBytes(ClipboardFormat format) { return(GetFormatObject(format.Id, new BytesDataConverter())); }
/// <summary> /// Tries to get a typed clipboard format as bytes from the current clipboard. Returns false /// if the format does not exist, or fails for another reason. /// </summary> public virtual bool TryGetFormatBytes(ClipboardFormat format, out byte[] bytes) { return(TryGetFormatObject(format.Id, new BytesDataConverter(), out bytes)); }
/// <summary> /// Retrieves a typed clipboard format object from the current clipboard. Throws exception if /// the format is not currently on the clipboard. /// </summary> public virtual T GetFormatType <T>(ClipboardFormat <T> format) { return(GetFormatObject(format.Id, format.TypeObjectReader)); }
/// <summary> /// Tries to get a typed clipboard format object from the current clipboard. Returns false /// if the format does not exist, or fails for another reason. /// </summary> public virtual bool TryGetFormatType <T>(ClipboardFormat <T> format, out T value) { return(TryGetFormatObject(format.Id, format.TypeObjectReader, out value)); }