C#WebBrowser与IE问题 [英] C# WebBrowser vs IE issue

查看:89
本文介绍了C#WebBrowser与IE问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经搜寻了2天,没有运气.

我在webBrowser控件中使用以下代码复制其实际内容( 后面的html代码):

Hi,

I have been googling for 2 days with no luck.

I am using the following code with webBrowser Control to copy it''s actual contents (NOT the html code behind):

private void button4_Click(object sender, EventArgs e)
        {
            webBrowser1.Document.ExecCommand("SelectAll", false, null);
            webBrowser1.Document.ExecCommand("Copy", false, null);
        }



而且这段代码运行良好.

问题是,我需要在IE中打开的任何网页上执行完全相同的操作,并且应该在某些button_click事件中通过c#应用程序完成此操作.

是否有人知道如何或正在做这样的事情实际上是可能的.

我一直在看一些有关挂钩和获取IE句柄的文章,但没有实际的工作示例.

感谢您的任何帮助,在此先多谢了



And this code is working perfectly.

The problem is that I need to do the same thing exactly on any web page that is opened in my IE ,, and that should be done from my c# application on some button_click event.

Does any one knows how or is doing such a thing actually possible.

I have been looking at some articles about hooking and getting a handle for IE and so but with no actual working example.

Any help is appreciated and so many thanks in advance

推荐答案

您好,

您可以通过使用OLE自动化来做到这一点.

首先将COM引用添加到SHDocVw.如果没有互操作,VS可以自动为您创建它,在工具框中,选择选择项目",然后在Com组件中选择Microsoft Web浏览器,将Microsoft Web浏览器拖到窗体上并将其删除,这使VS创建所有互操作并添加您将需要的所有引用.

这是代码:

Hello,

You can do it by using OLE automation.

First add a COM reference to SHDocVw. If you don''t have the interop, VS can create it for you automatically, In the tool box, select "Select Items", then in the Com component select Microsoft Web Browser, drag a Microsoft Web Browser on you form and delete it, this make VS creates all the interops and add all the references you will need.

And this is the code:

SHDocVw.ShellWindows shellWindows = new ShellWindowsClass();
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
    if (!String.IsNullOrEmpty(ie.LocationURL))
    {
        ie.ExecWB(OLECMDID.OLECMDID_SELECTALL, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER);
        ie.ExecWB(OLECMDID.OLECMDID_COPY, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER);
    }
}



请注意,您将需要测试LocationURL循环是否将返回,即窗口以及Windows资源管理器窗口.

Valery.



Be aware that you will need to test LocationURL has the loop will return ie windows as well as Windows explorer windows.

Valery.


非常感谢您的答复,我将立即对其进行测试,以查看最终的结果.
再次非常感谢.
Thanks a lot for reply, I am going to test it right away and see what I will end with.
So many thanks again.


这篇关于C#WebBrowser与IE问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆