Back to Devexpress

ClipboardAccessPolicy.Clearing Event

corelibraries-devexpress-dot-data-dot-utils-dot-clipboardaccesspolicy-5aa7a2e6.md

latest6.4 KB
Original Source

ClipboardAccessPolicy.Clearing Event

Fires when a DevExpress UI control attempts to clear the clipboard and allows you to allow (or cancel) the operation.

Namespace : DevExpress.Data.Utils

Assembly : DevExpress.Data.Desktop.v25.2.dll

NuGet Packages : DevExpress.Data.Desktop, DevExpress.ExpressApp.Win.Design

Declaration

csharp
public static event EventHandler<ClipboardAccessPolicy.ClipboardOperationRequestEventArgs> Clearing
vb
Public Shared Event Clearing As EventHandler(Of ClipboardAccessPolicy.ClipboardOperationRequestEventArgs)

Event Data

The Clearing event's data class is ClipboardAccessPolicy.ClipboardOperationRequestEventArgs. The following properties provide information specific to this event:

PropertyDescription
CancelGets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
DataFormatGets the data format.
DataObjectGets an object that defines a format-independent mechanism for transferring data.
IsClearOperationGets a value that indicates whether the clipboard clear operation is being processed.
IsCopyOperationGets a value that indicates whether the copy-to-clipboard operation is being processed.
IsDataObjectRequested
IsPasteOperationGets a value that indicates whether the paste-from-clipboard operation is being processed.
IsUIStateQueryGets a value that indicates whether a DevExpress UI control requests a copy/paste operation to update its UI (for example, menu commands).
OperationGets the clipboard-related operation being processed.

The event data class exposes the following methods:

MethodDescription
ToString()Returns a string representation of the current object.

Remarks

DevExpress controls clear the clipboard on demand. The Clipboard Access Policy fires the Clearing event when a DevExpress UI control attempts to clear the clipboard. Handle the Clearing event to allow (or cancel) the operation based on a specific condition. Use the e.Cancel parameter to allow or cancel the operation.

The following example demonstrates how to allow DevExpress UI controls to clear the clipboard if the clipboard containts data in ANSI text format. If the clipboard contains data in a different format, the operation is canceled:

csharp
using System;
using System.Windows.Forms;
using DevExpress.Data.Utils;

namespace DXApplication {
    internal static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ClipboardAccessPolicy.SuppressClearOperations();
            ClipboardAccessPolicy.Clearing += ClipboardAccessPolicy_Clearing;
            Application.Run(new Form1());
        }
        private static void ClipboardAccessPolicy_Clearing(object sender, ClipboardAccessPolicy.ClipboardOperationRequestEventArgs e) {
            if (e.DataFormat == DataFormats.Text)
                e.Cancel = false;
        }
    }
}
vb
Imports System
Imports System.Windows.Forms
Imports DevExpress.Data.Utils

Namespace DXApplication
    Friend Module Program
        ''' <summary>
        ''' The main entry point for the application.
        ''' </summary>
        <STAThread>
        Sub Main()
            Application.EnableVisualStyles()
            Application.SetCompatibleTextRenderingDefault(False)
            ClipboardAccessPolicy.SuppressClearOperations()
            AddHandler ClipboardAccessPolicy.Clearing, AddressOf ClipboardAccessPolicy_Clearing
            Application.Run(New Form1())
        End Sub
        Private Sub ClipboardAccessPolicy_Clearing(ByVal sender As Object, ByVal e As ClipboardAccessPolicy.ClipboardOperationRequestEventArgs)
            If e.DataFormat = DataFormats.Text Then
                e.Cancel = False
            End If
        End Sub
    End Module
End Namespace

Read the following topic for additional information: Clipboard Access Policy.

See Also

SuppressClearOperations()

ClipboardAccessPolicy Class

ClipboardAccessPolicy Members

DevExpress.Data.Utils Namespace