corelibraries-devexpress-dot-data-dot-utils-dot-clipboardaccesspolicy-e9c3bb2f.md
Applies a policy that suppresses all clipboard-related operations in DevExpress WinForms and WPF controls.
Namespace : DevExpress.Data.Utils
Assembly : DevExpress.Data.Desktop.v25.2.dll
NuGet Packages : DevExpress.Data.Desktop, DevExpress.ExpressApp.Win.Design
public static void ThrowAlways()
Public Shared Sub ThrowAlways
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());
}
}
}
Imports System
Imports System.Windows.Forms
Imports DevExpress.Data.Utils
Imports DevExpress.Data.Internal
Namespace DXApplication
Friend Module Program
''' <summary>
''' The main entry point for the application.
''' </summary>
<STAThread>
Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
ClipboardAccessPolicy.AllowOperation(ClipboardOperation.Copy, DataFormats.Text)
ClipboardAccessPolicy.ThrowAlways()
Application.Run(New Form1())
End Sub
End Module
End Namespace
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;
}
}
}
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