webbrowser控件怎样调用嵌入资源中的网页?

cgl4134 2014-03-27 01:11:52

// webBrowser1
//
this.webBrowser1.CausesValidation = false;
this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
this.webBrowser1.Location = new System.Drawing.Point(3, 3);
this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
this.webBrowser1.Name = "webBrowser1";
this.webBrowser1.Size = new System.Drawing.Size(681, 190);
this.webBrowser1.TabIndex = 0;
this.webBrowser1.Url = new System.Uri("d:\\a\\a.html", System.UriKind.Absolute);


一个简单的 webbrowser 控件,url指向本地d盘的一个网页文件,我想把这个路径换成嵌入资源中的网页,代码应该怎么写呢?
...全文
301 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
宝_爸 2014-03-28
  • 打赏
  • 举报
回复
可能是网页的问题,也可能是WebBrowser的问题。
cgl4134 2014-03-28
  • 打赏
  • 举报
回复
引用 8 楼 findcaiyzh 的回复:
不是,Properties下面有个Resources.resx,双击。 资源窗口工具栏上Add Resources -> Add existing resource. 加入你的html文件。 在程序中就可以通过Properties.Resources.<资源名称> 来取得资源的内容了。 string htmlString = Properties.Resources.Wilcom_API_Software_Subscription_Agreement_Final_7_3_14___clean;
可以调用了,,, 但是,网页中的js代码访问异常 - -
宝_爸 2014-03-28
  • 打赏
  • 举报
回复
不是,Properties下面有个Resources.resx,双击。 资源窗口工具栏上Add Resources -> Add existing resource. 加入你的html文件。 在程序中就可以通过Properties.Resources.<资源名称> 来取得资源的内容了。 string htmlString = Properties.Resources.Wilcom_API_Software_Subscription_Agreement_Final_7_3_14___clean;
cgl4134 2014-03-28
  • 打赏
  • 举报
回复
引用 6 楼 findcaiyzh 的回复:
你的资源是怎么弄得啊。




这样对不对啊.. 我刚接触c#编程的.. 能说下具体的操作过程吗- -
宝_爸 2014-03-27
  • 打赏
  • 举报
回复
你的资源是怎么弄得啊。
cgl4134 2014-03-27
  • 打赏
  • 举报
回复
DocumentText 使用这个 也是报错的, 命名空间“WindowsFormsApplication2”中不存在类型或命名空间名称“Properties”。是否缺少程序集引用?
cgl4134 2014-03-27
  • 打赏
  • 举报
回复
引用 3 楼 findcaiyzh 的回复:
在load事件里做,试一试。
还是 null
宝_爸 2014-03-27
  • 打赏
  • 举报
回复
在load事件里做,试一试。
cgl4134 2014-03-27
  • 打赏
  • 举报
回复

 // webBrowser1
            // 
            this.webBrowser1.CausesValidation = false;
            this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.webBrowser1.Location = new System.Drawing.Point(3, 3);
            this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
            this.webBrowser1.Name = "webBrowser1";
            this.webBrowser1.Size = new System.Drawing.Size(681, 190);
            this.webBrowser1.TabIndex = 0;
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("a.html"))
            {   
                
                using (StreamReader reader = new StreamReader(stream))
                {
                    webBrowser1.DocumentText = reader.ReadToEnd();
                }
            }
这样写,获取到的stream 为 null 哪的错误呢?
宝_爸 2014-03-27
  • 打赏
  • 举报
回复
使用DocumentText 属性 webBrowser1.DocumentText = WindowsFormsApplication1.Properties.Resources.htm; 或者使用stream: using (Stream stream = Assembly.GetExecutingAssembly() .GetManifestResourceStream("1.htm")) { using (StreamReader reader = new StreamReader(stream)) { webBrowser1.DocumentText = reader.ReadToEnd(); } } 来自 http://stackoverflow.com/questions/10598087/webbrowser-in-windows-forms-how-to-load-html-page-from-resources

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧