Class Clipboard
Provides methods for accessing the system clipboard, both for reading information from other processes and publishing information of its own
public static class Clipboard
- Inheritance
-
Clipboard
- Inherited Members
Remarks
For interaction with the clipboard to be available, the Video sub system must be initialized (either while initializing SDL or by initializing it on its own).
Methods
HasData(string)
Determines whether there is data in the clipboard for the provided mime type
public static bool HasData(string mimeType)
Parameters
mimeTypestringThe mime type to check for data in the clipboard
Returns
Remarks
This method should only be called on the main thread.
HasText()
Determines whether there is textual data available on the clipboard and it's not an empty string
public static bool HasText()
Returns
Remarks
This method should only be called on the main thread.
TryClearData()
Tries to clear the clipboard data
public static bool TryClearData()
Returns
- bool
true, if the clipboard was cleared successfully; otherwise,false(check TryGet(out string?) for more information)
Remarks
This method should only be called on the main thread.
TryGetData(string, out byte[]?)
Tries to get the clipboard data for a given mime type
public static bool TryGetData(string mimeType, out byte[]? data)
Parameters
mimeTypestringThe mime type to read from the clipboard
databyte[]The clipboard data for the specified mime type, or
nullif the clipboard was not successfully obtained
Returns
- bool
true, if the clipboard data for the specified mime type was successfully obtained; otherwise,false(check TryGet(out string?) for more information)
Remarks
Note: Textual data (e.g. UTF8 encoded text) might not be null terminated.
To get textual data from the clipboard, you can conveniently use TryGetText(out string?) instead.
This method should only be called on the main thread.
TryGetMimeTypes(out string[]?)
Tries to retrieve a list of mime types available in the clipboard
public static bool TryGetMimeTypes(out string[]? mimeTypes)
Parameters
mimeTypesstring[]The list of mime types available in the clipboard, or
nullif the list of mime types was not successfully obtained
Returns
- bool
true, if the list of mime types available in the clipboard was successfully obtained; otherwise,false(check TryGet(out string?) for more information)
Remarks
This method should only be called on the main thread.
TryGetText(out string?)
Tries to get text from the clipboard
public static bool TryGetText(out string? text)
Parameters
textstringThe text from the clipboard, or
nullif textual data from the clipboard couldn't get successfully obtained
Returns
- bool
true, if textual data from the clipboard was successfully obtained; otherwise,false(check TryGet(out string?) for more information)
Remarks
This method may result an empty string for text, if there was not enough memory left for a copy of the clipboard's content.
This method should only be called on the main thread.
TrySetData(DataGetter, params ReadOnlySpan<string>)
Tries to offer clipboard data for a given collection of mime types to the operating system
public static bool TrySetData(Clipboard.DataGetter dataGetter, params ReadOnlySpan<string> mimeTypes)
Parameters
dataGetterClipboard.DataGetterA Clipboard.DataGetter delegate which gets invoked when data for a specific mime type from the
mimeTypescollection is requestedmimeTypesReadOnlySpan<string>A collection of mime types to offer clipboard data for
Returns
- bool
true, if the clipboard data was successfully offered to the operating system; otherwise,false(check TryGet(out string?) for more information)
Remarks
This method just tells the operating system that the application is offering clipboard data for each of the provided mime types.
Once another application requests the data for a specific mime type, the provided dataGetter delegate will be invoked, allowing it to generate and respond with the data for the requested mime type.
Textual data (e.g. UTF8 encoded text) does not need to be null terminated (e.g. you can directly copy a portion of a document).
To set textual data for the clipboard, you can conveniently use TrySetText(string) instead.
This method should only be called on the main thread.
TrySetText(string)
Tries to set textual data for the clipboard
public static bool TrySetText(string text)
Parameters
textstringThe text to store in the clipboard
Returns
- bool
true, if the textual data was successfully stored in the clipboard; otherwise,false(check TryGet(out string?) for more information)
Remarks
This method should only be called on the main thread.