如何更改TChromium组件默认背景色? [英] How to change default background color for TChromium component?
问题描述
我使用 TChromium
一>。我分配 AWebPageAsString
这是带有灰色背景颜色的静态HTML页面。
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 ?
推荐答案
相当晚的答案,我知道,但它至少一个有趣的话题。要更改默认浏览器的背景颜色,您可以使用自定义样式表。这听起来不错,但它有一个很大的弱点 - 当您导航到具有例如一个页面没有样式表中定义,自定义的人会被应用。但是,如果你知道你会如浏览只有你在某种风格的页面,它可能会更有利的,因为那你就不用在默认自定义样式定义的样式定义。
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.
因此,要创建一个黑色背景的浏览器(使用下面描述的风格),可以使用此code:
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;
在上面的code中使用的 CSSBase64
不变的是下面的样式表的 连接codeD为Base64
:
The CSSBase64
constant used in the above code is the following stylesheet encoded to Base64
:
body {background-color:black;}
这篇关于如何更改TChromium组件默认背景色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!