将图像元素添加到Web浏览器控制页面(现有站点) [英] Adding a image element to a webbrowser control page (existing site)
本文介绍了将图像元素添加到Web浏览器控制页面(现有站点)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Windows窗体Webbrowser控件现有站点的图像创建元素.然后,我想将创建的元素移动到某个位置.我有此代码,但无法正常工作.
I'm trying to create an element with a image to a windows forms webbrowser control existing site. Then I want to move the created element to a certain position. I have this code, but it doesn't work.
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.GetElementById("gpu_notice").Style = "display:none";
webBrowser1.Document.GetElementById("header").OuterHtml = "";
webBrowser1.Document.GetElementById("ads").OuterHtml = "";
webBrowser1.Document.GetElementById("the_game").Style += "position: absolute; top: 0px; right: 0px;";
HtmlElement logo = webBrowser1.Document.CreateElement("logo");
logo.SetAttribute("SRC", @"C:\Users\Susana\Documents\Projeto HaxballK\Design\Logo HK.png");
webBrowser1.Document.Body.AppendChild(logo);
logo.SetAttribute("float", "right");
}
推荐答案
You have to use "img" tag instead of "logo" and set the file path with using file protocol.
HtmlElement logo = webBrowser1.Document.CreateElement("img");
logo.SetAttribute("SRC", @"file:///C:/Users/Susana/Documents/Projeto HaxballK/Design/Logo HK.png");
webBrowser1.Document.Body.AppendChild(logo);
logo.SetAttribute("float", "right");
已更新
如果要在所有JavaScript初始化运行之后添加图像,只需使用一个关闭的 Timer
.
If you want to add the image after all the JavaScript initializations have run, simply use one off Timer
.
System.Windows.Forms.Timer timer = new Timer();
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
// other processes
timer.Interval = 1 * 1000 * 5; // 5 seconds
timer.Tick += timer_Tick;
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
timer.Tick -= timer_Tick;
HtmlElement logo = webBrowser1.Document.CreateElement("img");
logo.SetAttribute("SRC", @"file:///C:/Users/Susana/Documents/Projeto HaxballK/Design/Logo HK.png");
webBrowser1.Document.Body.AppendChild(logo);
logo.SetAttribute("float", "right");
}
这篇关于将图像元素添加到Web浏览器控制页面(现有站点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文