-
Notifications
You must be signed in to change notification settings - Fork 0
Clipboard
Perform copy and paste operations on the system clipboard.
The Electron.Clipboard API provides comprehensive access to the system clipboard, supporting multiple data formats including text, HTML, RTF, images, and custom data. It enables reading from and writing to the clipboard with platform-specific behavior.
Parameters:
-
type(optional) - Clipboard type
Returns: The content in the clipboard as plain text.
Description: Read the content in the clipboard as plain text.
Parameters:
-
text- Text content to write -
type(optional) - Clipboard type
Description: Writes the text into the clipboard as plain text.
Parameters:
-
type(optional) - Clipboard type
Returns: The content in the clipboard as markup.
Description: Read the content in the clipboard as HTML markup.
Parameters:
-
markup- HTML markup to write -
type(optional) - Clipboard type
Description: Writes markup to the clipboard.
Parameters:
-
type(optional) - Clipboard type
Returns: The content in the clipboard as RTF.
Description: Read the content in the clipboard as RTF.
Parameters:
-
text- RTF content to write -
type(optional) - Clipboard type
Description: Writes the text into the clipboard in RTF.
Returns: Object containing title and url keys representing the bookmark in the clipboard.
Description: Returns an Object containing title and url keys representing the bookmark in the clipboard. The title and url values will be empty strings when the bookmark is unavailable.
Parameters:
-
title- Bookmark title -
url- Bookmark URL -
type(optional) - Clipboard type
Description: Writes the title and url into the clipboard as a bookmark.
Returns: The text on the find pasteboard.
Description: macOS: The text on the find pasteboard. This method uses synchronous IPC when called from the renderer process.
Parameters:
-
text- Text to write to find pasteboard
Description: macOS: Writes the text into the find pasteboard as plain text.
Parameters:
-
type(optional) - Clipboard type
Description: Clears the clipboard content.
Parameters:
-
type(optional) - Clipboard type
Returns: An array of supported formats for the clipboard type.
Description: Get an array of supported formats for the clipboard type.
Parameters:
-
data- Data object to write -
type(optional) - Clipboard type
Description: Writes data to the clipboard.
Parameters:
-
type(optional) - Clipboard type
Returns: An image from the clipboard.
Description: Read an image from the clipboard.
Parameters:
-
image- Image to write to clipboard -
type(optional) - Clipboard type
Description: Writes an image to the clipboard.
// Read text from clipboard
var text = await Electron.Clipboard.ReadTextAsync();
Console.WriteLine($"Clipboard text: {text}");
// Write text to clipboard
Electron.Clipboard.WriteText("Hello, Electron.NET!");
// Read with specific type
var html = await Electron.Clipboard.ReadHTMLAsync("public.main");// Copy formatted text
var htmlContent = "<h1>Title</h1><p>Some <strong>bold</strong> text</p>";
Electron.Clipboard.WriteHTML(htmlContent);
// Read RTF content
var rtf = await Electron.Clipboard.ReadRTFAsync();
Console.WriteLine($"RTF content: {rtf}");// Read image from clipboard
var image = await Electron.Clipboard.ReadImageAsync();
if (image != null)
{
Console.WriteLine($"Image size: {image.Size.Width}x{image.Size.Height}");
}
// Write image to clipboard
var nativeImage = NativeImage.CreateFromPath("screenshot.png");
Electron.Clipboard.WriteImage(nativeImage);// Read bookmark from clipboard
var bookmark = await Electron.Clipboard.ReadBookmarkAsync();
if (!string.IsNullOrEmpty(bookmark.Title))
{
Console.WriteLine($"Bookmark: {bookmark.Title} -> {bookmark.Url}");
}
// Write bookmark to clipboard
Electron.Clipboard.WriteBookmark("Electron.NET", "https://github.com/ElectronNET/Electron.NET");// Check available formats
var formats = await Electron.Clipboard.AvailableFormatsAsync();
Console.WriteLine($"Available formats: {string.Join(", ", formats)}");
// Clear clipboard
Electron.Clipboard.Clear();
// Write custom data
var data = new Data
{
Text = "Custom data",
Html = "<p>Custom HTML</p>",
Image = nativeImage
};
Electron.Clipboard.Write(data);// macOS specific find pasteboard operations
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
// Read find text
var findText = await Electron.Clipboard.ReadFindTextAsync();
Console.WriteLine($"Find text: {findText}");
// Write find text
Electron.Clipboard.WriteFindText("search term");
}- Electron.Shell - Work with file paths from clipboard
- Electron.Notification - Show clipboard operation results
- Electron Clipboard Documentation - Official Electron clipboard API
Want to contribute to this documentation? Please fork and create a PR! The Wiki is autogenerated from the /docs content in the repository.