From a8db4abdb40af298bfa930335ad5cf7a6c8c1ba4 Mon Sep 17 00:00:00 2001 From: russkyc Date: Thu, 6 Nov 2025 10:25:10 +0800 Subject: [PATCH 1/2] Support setting webview background color --- WebViewControl/GlobalSettings.cs | 10 ++++++++++ WebViewControl/WebViewLoader.cs | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/WebViewControl/GlobalSettings.cs b/WebViewControl/GlobalSettings.cs index 1482b352..9ddd6e70 100644 --- a/WebViewControl/GlobalSettings.cs +++ b/WebViewControl/GlobalSettings.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.IO; using Xilium.CefGlue.Common; @@ -7,6 +8,7 @@ namespace WebViewControl { public class GlobalSettings { + private Color backgroundColor = Color.White; private bool persistCache; private bool enableErrorLogOnly; private bool osrEnabled = false; @@ -25,6 +27,14 @@ public void AddCommandLineSwitch(string key, string value) { public IEnumerable> CommandLineSwitches => commandLineSwitches; + public Color BackgroundColor { + get => backgroundColor; + set { + EnsureNotLoaded(nameof(BackgroundColor)); + backgroundColor = value; + } + } + public string CachePath { get => cachePath; set { diff --git a/WebViewControl/WebViewLoader.cs b/WebViewControl/WebViewLoader.cs index 0b2feed7..e6d09678 100644 --- a/WebViewControl/WebViewLoader.cs +++ b/WebViewControl/WebViewLoader.cs @@ -37,7 +37,8 @@ public static void Initialize(GlobalSettings settings) { CachePath = settings.CachePath, // enable cache for external resources to speedup loading WindowlessRenderingEnabled = settings.OsrEnabled, RemoteDebuggingPort = settings.GetRemoteDebuggingPort(), - UserAgent = settings.UserAgent + UserAgent = settings.UserAgent, + BackgroundColor = new CefColor(settings.BackgroundColor.A, settings.BackgroundColor.R, settings.BackgroundColor.G, settings.BackgroundColor.B), }; var customSchemes = CustomSchemes.Select(s => new CustomScheme() { From 241090ecb0c391d9334e0094e60e3ebf9ba5cf00 Mon Sep 17 00:00:00 2001 From: russkyc Date: Thu, 6 Nov 2025 10:43:42 +0800 Subject: [PATCH 2/2] Refactor setting background color to use ToArgb() --- WebViewControl/WebViewLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebViewControl/WebViewLoader.cs b/WebViewControl/WebViewLoader.cs index e6d09678..4a598701 100644 --- a/WebViewControl/WebViewLoader.cs +++ b/WebViewControl/WebViewLoader.cs @@ -38,7 +38,7 @@ public static void Initialize(GlobalSettings settings) { WindowlessRenderingEnabled = settings.OsrEnabled, RemoteDebuggingPort = settings.GetRemoteDebuggingPort(), UserAgent = settings.UserAgent, - BackgroundColor = new CefColor(settings.BackgroundColor.A, settings.BackgroundColor.R, settings.BackgroundColor.G, settings.BackgroundColor.B), + BackgroundColor = new CefColor((uint)settings.BackgroundColor.ToArgb()) }; var customSchemes = CustomSchemes.Select(s => new CustomScheme() {