2015-10-18 71 views
-1

是否可以在Windows Forms WebBrowser控件中更改一个html元素的位置?我已经有这样的:在Windows Forms WebBrowser中更改html元素的位置WebBrowser

public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    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 = ""; 
     // move element "the_game" here 
    } 
} 
} 

下一步将移动元素...

+0

你可以注入JavaScript,反过来可以修改DOM http://stackoverflow.com/questions/153748/how-to-inject-javascript-in-webbrowser-control或者你可以直接加载动态创建的DOM到控制。 – Wobbles

+0

@Wobbles刚刚编辑了问题。 –

+0

“the_game”元素的定义在哪里?你可以注入jquery来处理这个问题,如果你在你的文档中包含jquery库,并使用.append()和.detach() – Wobbles

回答

1

您可以通过添加position属性Style这样的移动the_game元素。

var game = webBrowser1.Document.GetElementById("the_game");    
game.Style += "position: absolute; top: 50px; right: 20px;"; 

我会推荐阅读this并了解如何使用它。

+0

我无法更改我正在使用的网页的Html。 –

+0

然后,获取您想要使用GetElementById()方法移动游戏元素的元素,并追加游戏的OuterHtml。 'dest.OuterHtml + = game.OuterHtml'。 – jhmt

+0

等一下,但我说的是在页面中移动,改变他的x和y ... –