Back to Devexpress

ClipboardAccessPolicy.Failed Event

corelibraries-devexpress-dot-data-dot-utils-dot-clipboardaccesspolicy-8a332a70.md

latest6.4 KB
Original Source

ClipboardAccessPolicy.Failed Event

Allows you to respond to associated failures.

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.FailedEventArgs> Failed
vb
Public Shared Event Failed As EventHandler(Of ClipboardAccessPolicy.FailedEventArgs)

Event Data

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

PropertyDescription
DataFormatGets the data format. Inherited from ClipboardAccessPolicy.ClipboardOperationEventArgs.
DataObjectGets an object that defines a format-independent mechanism for transferring data. Inherited from ClipboardAccessPolicy.ClipboardOperationEventArgs.
ExceptionGets the exception.
IsClearOperationGets a value that indicates whether the clipboard clear operation is being processed. Inherited from ClipboardAccessPolicy.ClipboardOperationEventArgs.
IsCopyOperationGets a value that indicates whether the copy-to-clipboard operation is being processed. Inherited from ClipboardAccessPolicy.ClipboardOperationEventArgs.
IsPasteOperationGets a value that indicates whether the paste-from-clipboard operation is being processed. Inherited from ClipboardAccessPolicy.ClipboardOperationEventArgs.
OperationGets the clipboard-related operation being processed. Inherited from ClipboardAccessPolicy.ClipboardOperationEventArgs.
ThrowGets or sets whether to throw an exception.

The event data class exposes the following methods:

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

Remarks

The ThrowAlways() method disables all clipboard-related operations (copy, paste, clear) in DevExpress WinForms and WPF controls. The Clipboard Access Policy throws an exception when a user or UI control attempts to perform an operation with the clipboard.

Handle the Failed event to respond to associated failures:

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.ThrowAlways();
            ClipboardAccessPolicy.Failed += ClipboardAccessPolicy_Failed;
            Application.Run(new Form1());
        }
        private static void ClipboardAccessPolicy_Failed(object sender, ClipboardAccessPolicy.FailedEventArgs e) {
            if (e.DataFormat == DataFormats.Text)
                e.Throw = 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.ThrowAlways()
            AddHandler ClipboardAccessPolicy.Failed, AddressOf ClipboardAccessPolicy_Failed
            Application.Run(New Form1())
        End Sub
        Private Sub ClipboardAccessPolicy_Failed(ByVal sender As Object, ByVal e As ClipboardAccessPolicy.FailedEventArgs)
            If e.DataFormat = DataFormats.Text Then
                e.Throw = False
            End If
        End Sub
    End Module
End Namespace

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

See Also

ThrowAlways()

ClipboardAccessPolicy Class

ClipboardAccessPolicy Members

DevExpress.Data.Utils Namespace