none
RRS feed

全部回复

  • 我写了一个简单的demo, 你可以看下。

    C# code:

     private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                webbrowser.Navigate("http://www.baidu.com/");
                webbrowser.DocumentCompleted+=new WebBrowserDocumentCompletedEventHandler(webbrowser_DocumentCompleted);
            }
    
            private bool flag = false;
            private void webbrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                if (webbrowser.ReadyState != WebBrowserReadyState.Complete)
                {
                    return;
                }
                else
                {
                    if (flag == false)
                    {
                        webbrowser.Document.Click += new HtmlElementEventHandler(Document_Click);
                    }
                    flag = true;
                }
                
            }
            private void Document_Click(Object sender, HtmlElementEventArgs e)
            {
                if (webbrowser.Document != null)
                {
                    HtmlElement elem = webbrowser.Document.GetElementFromPoint(e.ClientMousePosition);
                    Console.WriteLine(elem.GetAttribute("id"));
                }
            }

    Xaml code:

        <Grid>
            <WindowsFormsHost>
                <wf:WebBrowser x:Name="webbrowser" />
            </WindowsFormsHost>
        </Grid>
    希望可以帮到你!

    Kee Poppy [MSFT]
    MSDN Community Support | Feedback to us

    2012年7月2日 9:59
    版主