如何更改 TChromium 组件的默认背景颜色?

发布于 2024-12-22 22:38:18 字数 617 浏览 5 评论 0原文

我使用 TChromium。我指定 AWebPageAsString 这是一个带有灰色背景颜色的静态 HTML 页面。

FBrowser := TChromium.Create(pnlHolder);
FBrowser.Visible := false;
FBrowser.Parent := TWinControl(pnlHolder);
FBrowser.Align := alClient;
FBrowser.OnBeforeBrowse := BrowserBeforeBrowse;
FBrowser.HandleNeeded;
FBrowser.FontOptions.RemoteFontsDisabled := true;
FBrowser.Browser.MainFrame.LoadString(AWebPageAsString, 'navigate:webpage');

当我启动应用程序时,它首先显示为白色背景和空内容,然后我的页面显示为灰色背景和实际内容。

有办法避免这种情况吗?也许有默认的背景颜色?

I use TChromium. I assign AWebPageAsString which is a static HTML page with a gray background color.

FBrowser := TChromium.Create(pnlHolder);
FBrowser.Visible := false;
FBrowser.Parent := TWinControl(pnlHolder);
FBrowser.Align := alClient;
FBrowser.OnBeforeBrowse := BrowserBeforeBrowse;
FBrowser.HandleNeeded;
FBrowser.FontOptions.RemoteFontsDisabled := true;
FBrowser.Browser.MainFrame.LoadString(AWebPageAsString, 'navigate:webpage');

When I start the application it is displayed first with white background and empty content and then my page gets displayed with gray background and actual content.

Is there a way to avoid this ? Maybe have a default background color ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倒带 2024-12-29 22:38:18

我知道,这是一个很晚的答案,但它至少是一个有趣的话题。要更改默认浏览器的背景颜色,您可以使用自定义样式表。听起来不错,但它有一个很大的弱点 - 当您导航到没有定义样式表的页面时,将应用您的自定义样式表。但是,如果您知道您将仅浏览特定样式的页面,那么这甚至可能是有利的,因为这样您就可以保留在默认自定义样式中定义的样式定义。

因此,要创建一个黑色背景的浏览器(使用下面描述的样式),您可以使用以下代码:

procedure TForm1.FormCreate(Sender: TObject);
const
  CSSHeader = 'data:text/css;charset=utf-8;base64,';
  CSSBase64 = 'Ym9keSB7YmFja2dyb3VuZC1jb2xvcjpibGFjazt9';
begin
  Chromium1.UserStyleSheetLocation := CSSHeader + CSSBase64;
  Chromium1.Options.UserStyleSheetEnabled := True;
  Chromium1.ReCreateBrowser('about:blank');
end;

上面代码中使用的 CSSBase64 常量是以下样式表 编码为 Base64

body {background-color:black;}

Quite a late answer, I know, but it's at least an interesting topic. To change default browser's background color you can use a custom stylesheet. It sounds good, but it has one big weakness - when you navigate to a page that has e.g. no stylesheet defined, your custom one will be applied. But if you know that you'll browse e.g. only your pages in a certain style, it might be even advantage, since then you can leave the style definitions defined in that default custom style.

So to create a browser with a black background (using the style described below) you can use this code:

procedure TForm1.FormCreate(Sender: TObject);
const
  CSSHeader = 'data:text/css;charset=utf-8;base64,';
  CSSBase64 = 'Ym9keSB7YmFja2dyb3VuZC1jb2xvcjpibGFjazt9';
begin
  Chromium1.UserStyleSheetLocation := CSSHeader + CSSBase64;
  Chromium1.Options.UserStyleSheetEnabled := True;
  Chromium1.ReCreateBrowser('about:blank');
end;

The CSSBase64 constant used in the above code is the following stylesheet encoded to Base64:

body {background-color:black;}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文