WebBrowser加载本地资源

加载的本地资源有两种情况:

一:加载程序集里面的资源信息

  1.加载html资源

    (1)

      StreamReader reader=Application.GetResourceStream(New Uri("path",UriKind.Relative).Stream;

      webBrowser.NavigateToString(reader.ReadToEnd());

    (2)

               引用命名空间: Microsoft.Xna.Framework;

      StreamReader reader = new StreamReader(TitleContainer.OpenStream("pathString"));

      webBrowser.NavigateToString(reader.ReadToEnd());

    (3)

     webBrowser.NavigateToString("htmlString");

    注:为了让显示的html页面能够进行交互,就需要让webBrowser具备支持脚本语言的功能,所以需要设置webBrowser.IsScriptEnabled = true;

 

  2.加载图片资源

    

二:加载程序的独立内存空间里面的资源信息

   1.加载html资源

    (1)

      VAR fe = IsolatedStorageFile.GetUserStoreForApplication());                    

      IsolatedStorageFileStream stream= fe.OpenFile("BOOK.HTML", FileMode.Open, FileAccess.Read);   

      StreamReader reader=new StreamReader(stream);             

      webBrowser.NavigateToString(reader.ReadToEnd()); 

        2.加载图片资源

      将网络图片资源保存在本地的空间上面,然后使用WebBrowser控件展示,

      ProductId:Windows phone 工程中的WMAppManifest.xml中的App节点的ProductId属性

      ContentDictionary:保存在本地存储控件的路径

      string html=""<html><head><title>title information</title></head><body>good morning </br>good afternoon</br><img width=\"300\" height=\"400\" src=\"file:///Applications/Data/{0}/Data/IsolatedStore/{1}\"></body></html>"
      html=String.Format(html,ProductId,ContentDictonary);

                webBrowser.NavigateToString(html);

 

转载于:https://www.cnblogs.com/mokey/archive/2011/11/17/2252775.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以通过在 MFC 中使用 `DWebBrowserEvents2` 接口来判断 `WebBrowser` 控件是否完成。具体实现步骤如下: 1. 在 MFC 对话框类的头文件中添以下内容: ``` class CMyDialog : public CDialogEx, public DWebBrowserEvents2 { // ... STDMETHOD(OnDocumentComplete)(IDispatch* pDisp, VARIANT* URL); // ... } ``` 2. 在 MFC 对话框类的源文件中添以下内容: ``` BEGIN_DISPATCH_MAP(CMyDialog, CDialogEx) DISP_FUNCTION_ID(CMyDialog, "OnDocumentComplete", 259, OnDocumentComplete, VT_EMPTY, VTS_DISPATCH VTS_PVARIANT) END_DISPATCH_MAP() STDMETHODIMP CMyDialog::OnDocumentComplete(IDispatch* pDisp, VARIANT* URL) { // 完成后的处理逻辑 return S_OK; } ``` 3. 在对话框的 `OnInitDialog` 函数中添以下代码: ``` // 获取 WebBrowser 控件对象 CWnd* pWnd = GetDlgItem(IDC_EXPLORER1); if (pWnd) { // 获取控件对象的 dispatch 指针 LPDISPATCH lpDispatch = pWnd->GetControlUnknown(); if (lpDispatch) { // 将 dispatch 指针转换为 WebBrowser 控件对象 CComPtr<IWebBrowser2> pWebBrowser2; lpDispatch->QueryInterface(IID_IWebBrowser2, (void**)&pWebBrowser2); if (pWebBrowser2) { // 注册 DWebBrowserEvents2 事件接口 CComPtr<IConnectionPointContainer> pConnectionPointContainer; pWebBrowser2->QueryInterface(IID_IConnectionPointContainer, (void**)&pConnectionPointContainer); if (pConnectionPointContainer) { CComPtr<IConnectionPoint> pConnectionPoint; pConnectionPointContainer->FindConnectionPoint(DIID_DWebBrowserEvents2, &pConnectionPoint); if (pConnectionPoint) { DWORD dwCookie; pConnectionPoint->Advise(this, &dwCookie); } } } } } ``` 4. 在 `OnDocumentComplete` 函数中添完成后的处理逻辑,例如: ``` STDMETHODIMP CMyDialog::OnDocumentComplete(IDispatch* pDisp, VARIANT* URL) { // 判断是否已完毕 CComPtr<IWebBrowser2> pWebBrowser2; pDisp->QueryInterface(IID_IWebBrowser2, (void**)&pWebBrowser2); if (pWebBrowser2 && pWebBrowser2->ReadyState == READYSTATE_COMPLETE) { // 完成后的处理逻辑 // ... } return S_OK; } ``` 这样,当 `WebBrowser` 控件完成后,就会自动调用 `OnDocumentComplete` 函数,从而触发相应的处理逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值