WindowsFormsSettings.ForcePaintApiDiagnostics(PaintApiDiagnosticsLevel, PaintApiTraceLevelResolver) Method
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.v24.2.dll
#Declaration
public static void ForcePaintApiDiagnostics(
PaintApiDiagnosticsLevel level,
PaintApiTraceLevelResolver resolver = null
)
#Parameters
Name | Type | Description |
---|---|---|
level | DevExpress. |
A enumerator value that specifies how the application responds to this inadvisable API. |
#Optional Parameters
Name | Type | Default | Description |
---|---|---|---|
resolver | DevExpress. |
null | An optional object that allows you to implement a custom trace behavior. |
#Remarks
The ForcePaintApiDiagnostics method allows you to detect the following issues:
- the Appearance.BackColor property modified for skinned UI elements - this setting was not functional for versions 18.1 and older, but changes the element’s background color starting with version 18.2. See Application Appearance and Skin Colors for the details.
- Custom draw methods performed via the Graphics class methods. See DirectX Hardware Acceleration to learn more.
- Incorrect inheritance in custom skins.
- Incorrect DPI Awareness activation.
Use the Throw diagnostics level to throw exceptions whenever the unsupported/outdated code is detected.
Other available diagnostics levels:
- Trace - unsupported APIs display result in warnings, displayed in Visual Studio’s “Output” window;
- Disable - ignores unsupported API;
- Default - acts as “Trace” if DirectX and\or Per-Monitor HiDPI support is enabled; otherwise, the same as “Disable”.
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;
});
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());
}
See this article for more information: Obtain an Exception’s Call Stack.