windowsforms-devexpress-dot-xtraeditors-dot-windowsformssettings-dot-forcepaintapidiagnostics-x28-devexpress-dot-utils-dot-diagnostics-dot-paintapidiagnosticslevel-devexpress-dot-utils-dot-diagnostics-dot-paintapitracelevelresolver-x29.md
Allows you to trace all outdated APIs that are not recommended for use with DirectX-rendered and Per-Monitor DPI-aware applications. Starting with version 18.2, also traces Appearance.BackColor properties modified for skinned UI elements.
Namespace : DevExpress.XtraEditors
Assembly : DevExpress.Utils.v25.2.dll
NuGet Packages : DevExpress.Utils, DevExpress.Wpf.Core
public static void ForcePaintApiDiagnostics(
PaintApiDiagnosticsLevel level,
PaintApiTraceLevelResolver resolver = null
)
Public Shared Sub ForcePaintApiDiagnostics(
level As PaintApiDiagnosticsLevel,
resolver As PaintApiTraceLevelResolver = Nothing
)
| Name | Type | Description |
|---|---|---|
| level | DevExpress.Utils.Diagnostics.PaintApiDiagnosticsLevel |
A enumerator value that specifies how the application responds to this inadvisable API.
|
| Name | Type | Default | Description |
|---|---|---|---|
| resolver | DevExpress.Utils.Diagnostics.PaintApiTraceLevelResolver | null |
An optional object that allows you to implement a custom trace behavior.
|
The ForcePaintApiDiagnostics method allows you to detect the following issues:
Use the Throw diagnostics level to throw exceptions whenever the unsupported/outdated code is detected.
WindowsFormsSettings.ForcePaintApiDiagnostics(PaintApiDiagnosticsLevel.Throw);
WindowsFormsSettings.ForcePaintApiDiagnostics(PaintApiDiagnosticsLevel.Throw)
Other available diagnostics levels:
csharpWindowsFormsSettings.ForcePaintApiDiagnostics(PaintApiDiagnosticsLevel.Trace);vbWindowsFormsSettings.ForcePaintApiDiagnostics(PaintApiDiagnosticsLevel.Trace)
The optional “resolver” parameter allows you to implement any custom trace behavior.
WindowsFormsSettings.ForcePaintApiDiagnostics(PaintApiDiagnosticsLevel.Trace, (apiLevel, api) => {
if(api == "ApiName") {
Console.WriteLine(apiLevel.ToString() + "This API is not recommended: " + api);
return PaintApiDiagnosticsLevel.Disable;
}
return apiLevel;
});
WindowsFormsSettings.ForcePaintApiDiagnostics(PaintApiDiagnosticsLevel.Trace, Function(apiLevel, api)
If api = "ApiName" Then
Console.WriteLine(apiLevel.ToString() & "This API is not recommended: " & api)
Return PaintApiDiagnosticsLevel.Disable
End If
Return apiLevel
End Function)
The code snippet below allows your app to write the method’s output to the “logfile.txt” file on the desktop.
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
WindowsFormsSettings.ForceDirectXPaint();
WindowsFormsSettings.ForcePaintApiDiagnostics(DevExpress.Utils.Diagnostics.PaintApiDiagnosticsLevel.Trace, (dlevel, api) => {
System.Text.StringBuilder msg = new System.Text.StringBuilder();
msg.AppendLine($@"Logged by ForcePaintApiDiagnostics: incorrect\obsolete API found -- {api}");
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace();
msg.AppendLine(st.ToString());
msg.AppendLine();
String desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string logFilePath = String.Format("{0}\\{1}", desktopPath, "logfile.txt");
System.IO.File.AppendAllText(logFilePath, msg.ToString());
return dlevel;
});
Application.Run(new Form2());
}
Private Shared Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
WindowsFormsSettings.ForceDirectXPaint()
WindowsFormsSettings.ForcePaintApiDiagnostics(DevExpress.Utils.Diagnostics.PaintApiDiagnosticsLevel.Trace, Function(dlevel, api)
Dim msg As System.Text.StringBuilder = New System.Text.StringBuilder()
msg.AppendLine($"Logged by ForcePaintApiDiagnostics: incorrect\obsolete API found -- {api}")
Dim st As System.Diagnostics.StackTrace = New System.Diagnostics.StackTrace()
msg.AppendLine(st.ToString())
msg.AppendLine()
Dim desktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim logFilePath As String = String.Format("{0}\{1}", desktopPath, "logfile.txt")
System.IO.File.AppendAllText(logFilePath, msg.ToString())
Return dlevel
End Function)
Application.Run(New Form2())
End Sub
See this article for more information: Obtain an Exception’s Call Stack.
See Also