![](/img/trans.png)
[英]How can i match the background color of a button with the foreground of another item
[英]How can I change a webpage's background and foreground color in a web browser element?
在我的应用程序中,我将一些HTML页面呈现为WebBrowser
元素。 在一些文章中,我发现WebBrowser的背景和前景颜色取决于HTML页面属性。
如何在程序中更改此HTML背景和前景色以查看自定义颜色?
您应该使用WebBrowser
控件的InvokeScript
方法注入一些Javascript代码,这些代码将依次更改背景和前景色等元素属性。
示例代码:
public MainPage()
{
InitializeComponent();
this.webBrowser1.IsScriptEnabled = true;
this.webBrowser1.Navigate(new Uri("http://yourpage.com/"));
this.webBrowser1.LoadCompleted += webBrowser1_LoadCompleted;
}
void webBrowser1_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
this.webBrowser1.InvokeScript("eval", new[] { "document.body.style.background = 'black';" });
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.