Skip to main content
All docs
V25.1
  • ClipboardAccessPolicy.ThrowAlways() Method

    Applies a policy that suppresses all clipboard-related operations in DevExpress WinForms and WPF controls.

    Namespace: DevExpress.Data.Utils

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

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

    Declaration

    public static void ThrowAlways()

    Remarks

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

    Use AllowOperation and/or AllowDataFormats methods to enable specific operations for all or certain data formats when the restrictive policy is enabled.

    using System;
    using System.Windows.Forms;
    using DevExpress.Data.Utils;
    using DevExpress.Data.Internal;
    
    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.AllowOperation(ClipboardOperation.Copy, DataFormats.Text);
                ClipboardAccessPolicy.ThrowAlways();
                Application.Run(new Form1());
            }
        }
    }
    

    Handle the Failed event to respond to associated failures:

    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;
            }
        }
    }
    

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

    See Also