c#操作axwebbrowser的一个简单示例

WebBrowser/AxWebBrowser使用 webBrowser 窗体简单使用 axWebBrowser 窗体简单使用 需要添加com组件----Microsoft web browser 组件 立即下载


最近在做一个程序中要求在WinForm中插一个浏览器的控件,在网上一找,找到了AxWebBrowser这个控件,它是一个COM的控件,所以先要往工具箱中添加这个控件,使得它能像其他可视化控件一样变得容易操作。添加完之后,你会在工具箱的“常规”箱中看到一个新增的控件,我们就能开始往WinForm中添加了! 
一看这个控件的方法和属性还是很多的,都是作为一个浏览器所应该有的,如GoBack(),GoFoward(),Stop(),Refresh(),Home()等等,可以看到在一般浏览器的顶端会有这些按钮,我们只要再加个ToolBar,加上相应的按钮,写好程序,就可以实现这些功能了。 

网上其实已经有很多用这个控件实现一个网页浏览器的程序,我找了一个先贴在这里: 

××××××××××××××××××××××××××××××××××××××××××××××××××××××××× 

通过转换后组件来实现浏览器的一些基本功能: 
浏览器的主要功能就是能够到指定的地址浏览信息,当然在具体的浏览中还有一些基本的功能,譬如:“前进”、“后退”、“停止”、“刷新”、“主页”等,这些功能都可以通过“AxWebBrowser”组件来实现。下面就来具体介绍: 
< I > .浏览指定的地址: 
在程序中,网址是填写在组件“textbox1”中的,“浏览指定地址”功能是通过程序的按钮“转到”来实现的。下面是按钮“转到”按动后的程序代m: 
private void button1_Click ( object sender , System.EventArgs e ) 
{ 
System.Object nullObject = 0 ; 
string str = "" ; 
System.Object nullObjStr = str ; 
Cursor.Current = Cursors.WaitCursor ; 
axWebBrowser1.Navigate ( textBox1.Text , ref nullObject , ref nullObjStr , ref nullObjStr , ref nullObjStr ) ; 
Cursor.Current = Cursors.Default ; 
} 
< II > .浏览器的“前进”、“后退”、“停止”、“刷新”、“主页”功能: 
在“AxWebBrowser”组件中对这些功能都有一个具体的方法来与之对应,具体如下面代m: 
private void toolBar1_ButtonClick ( object sender , ToolBarButtonClickEventArgs e ) 
{ 
//浏览器中的“后退” 
if ( e.Button == tb1 ) 
{ 
axWebBrowser1.GoBack ( ) ; 
} 
//浏览器中的“前进” 
if ( e.Button == tb2 ) 
{ 
axWebBrowser1.GoForward ( ) ; 
} 
//浏览器中的“停止” 
if ( e.Button == tb3 ) 
{ 
axWebBrowser1.Stop ( ) ; 
} 
//浏览器中的“刷新” 
if ( e.Button == tb4 ) 
{ 
axWebBrowser1.Refresh ( ) ; 
} 
//浏览器中的“主页” 
if ( e.Button == tb5 ) 
{ 
axWebBrowser1.GoHome ( ) ; 
} 

} 
< III > .当然掌握了上面的知识,你就可以用Visual C#做出一个基本的浏览器了,但下面这些也是不可缺少的,因为下面这些代m将使得你做的浏览器更专业。下面代m的作用是使得浏览界面随着窗体的变化而变化,按钮和文本框也要随着窗体的变化而变化。 
button1.Anchor = ( AnchorStyles.Top | AnchorStyles.Right ) ; 
//定位“转到”按钮组件与窗体的上、右边框保持一致 
textBox1.Anchor = ( ( AnchorStyles.Top | AnchorStyles.Left ) 
| AnchorStyles.Right ) ; 
//定位地址文本框组件与窗体的上、左、右边框保持一致 
axWebBrowser1.Anchor = ( ( ( AnchorStyles.Top | AnchorStyles.Bottom ) 
| AnchorStyles.Left ) 
| AnchorStyles.Right ) ; 
//定位浏览器组件与窗体的上、下、左、右边框保持一致 
源程序代m(brower.cs) 
了解有了上面的这些,就可以比较容易编写一个属于自己的浏览器了,下面是用Visual C#做的浏览器源程序代m,他具备了IE浏览器的一些常用的功能。 
using System ; 
using System.Drawing ; 
using System.Collections ; 
using System.ComponentModel ; 
using System.Windows.Forms ; 
using System.Data ; 
using AxSHDocVw ; 
public class Form1 : Form 
{ 
private ToolBar toolBar1 ; 
private ToolBarButton tb1 ; 
private ToolBarButton tb2 ; 
private ToolBarButton tb3 ; 
private ToolBarButton tb4 ; 
private ToolBarButton tb5 ; 
private Label label1 ; 
private TextBox textBox1 ; 
private Button button1 ; 
private AxWebBrowser axWebBrowser1 ; 
private System.ComponentModel.Container components = null ; 
public Form1 ( ) 
{ 
InitializeComponent ( ) ; 
} 
//清除程序中使用过的资源 
protected override void Dispose ( bool disposing ) 
{ 
if ( disposing ) 
{ 
if ( components != null ) 
{ 
components.Dispose ( ) ; 
} 
} 
base.Dispose ( disposing ) ; 
} 
//初始化窗体中的各个组件 
private void InitializeComponent ( ) 
{ 
tb1 = new ToolBarButton ( ) ; 
tb2 = new ToolBarButton ( ) ; 
tb3 = new ToolBarButton ( ) ; 
toolBar1 = new ToolBar ( ) ; 
tb4 = new ToolBarButton ( ) ; 
tb5 = new ToolBarButton ( ) ; 
button1 = new Button ( ) ; 
textBox1 = new TextBox ( ) ; 
axWebBrowser1 = new AxWebBrowser ( ) ; 
label1 = new Label ( ) ; 
( ( System.ComponentModel.ISupportInitialize ) ( this.axWebBrowser1 ) ).BeginInit ( ) ; 
this.SuspendLayout ( ) ; 

tb1.Text = "后退" ; 
tb2.Text = "前进" ; 
tb3.Text = "停止" ; 
tb4.Text = "刷新" ; 
tb5.Text = "主页" ; 

toolBar1.Appearance = ToolBarAppearance.Flat ; 
toolBar1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle ; 
//在工具栏中加入按钮 
toolBar1.Buttons.Add ( tb1 ) ; 
toolBar1.Buttons.Add ( tb2 ) ; 
toolBar1.Buttons.Add ( tb3 ) ; 
toolBar1.Buttons.Add ( tb4 ) ; 
toolBar1.Buttons.Add ( tb5 ) ; 
toolBar1.DropDownArrows = true ; 
toolBar1.Name = "toolBar1" ; 
toolBar1.ShowToolTips = true ; 
toolBar1.Size = new System.Drawing.Size ( 612 , 39 ) ; 
toolBar1.TabIndex = 0 ; 
toolBar1.ButtonClick += new ToolBarButtonClickEventHandler ( toolBar1_ButtonClick ) ; 
//定位“转到”按钮组件与窗体的上、右边框保持一致 
button1.Anchor = ( AnchorStyles.Top | AnchorStyles.Right ) ; 
button1.DialogResult = DialogResult.OK ; 
button1.Location = new System.Drawing.Point ( 544 , 45 ) ; 
button1.Name = "button1" ; 
button1.Size = new System.Drawing.Size ( 40 , 23 ) ; 
button1.TabIndex = 3 ; 
button1.Text = "转到" ; 
button1.Click += new System.EventHandler ( button1_Click ) ; 
//定位地址文本框组件与窗体的上、左、右边框保持一致 
textBox1.Anchor = ( ( AnchorStyles.Top | AnchorStyles.Left ) 
| AnchorStyles.Right ) ; 
textBox1.Location = new System.Drawing.Point ( 64 , 47 ) ; 
textBox1.Name = "textBox1" ; 
textBox1.Size = new System.Drawing.Size ( 464 , 21 ) ; 
textBox1.TabIndex = 2 ; 
textBox1.Text = "" ; 
//定位浏览器组件与窗体的上、下、左、右边框保持一致 
axWebBrowser1.Anchor = ( ( ( AnchorStyles.Top | AnchorStyles.Bottom ) 
| AnchorStyles.Left ) 
| AnchorStyles.Right ) ; 
axWebBrowser1.Enabled = true ; 
axWebBrowser1.Location = new System.Drawing.Point ( 0 , 72 ) ; 
axWebBrowser1.Size = new System.Drawing.Size ( 608 , 358 ) ; 
axWebBrowser1.TabIndex = 4 ; 

label1.Location = new System.Drawing.Point ( 16 , 48 ) ; 
label1.Name = "label1" ; 
label1.Size = new System.Drawing.Size ( 48 , 16 ) ; 
label1.TabIndex = 1 ; 
label1.Text = "地址:" ; 

this.AutoScaleBaseSize = new System.Drawing.Size ( 6 , 14 ) ; 
this.ClientSize = new System.Drawing.Size ( 612 , 433 ) ; 

this.Controls.Add ( axWebBrowser1 ) ; 
this.Controls.Add ( button1 ) ; 
this.Controls.Add ( textBox1 ) ; 
this.Controls.Add ( label1 ) ; 
this.Controls.Add ( toolBar1 ) ; 
this.FormBorderStyle = FormBorderStyle.FixedSingle ; 
this.Name = "Form1" ; 
this.Text = "visual C#做浏览器" ; 
( ( System.ComponentModel.ISupportInitialize ) ( this.axWebBrowser1 ) ).EndInit ( ) ; 
this.ResumeLayout ( false ) ; 

} 
static void Main ( ) 
{ 
Application.Run ( new Form1 ( ) ) ; 
} 
//实现浏览器主要功能 
private void toolBar1_ButtonClick ( object sender , ToolBarButtonClickEventArgs e ) 
{ 
//浏览器中的“后退” 
if ( e.Button == tb1 ) 
{ 
axWebBrowser1.GoBack ( ) ; 
} 
//浏览器中的“前进” 
if ( e.Button == tb2 ) 
{ 
axWebBrowser1.GoForward ( ) ; 
} 
//浏览器中的“停止” 
if ( e.Button == tb3 ) 
{ 
axWebBrowser1.Stop ( ) ; 
} 
//浏览器中的“刷新” 
if ( e.Button == tb4 ) 
{ 
axWebBrowser1.Refresh ( ) ; 
} 
//浏览器中的“主页” 
if ( e.Button == tb5 ) 
{ 
axWebBrowser1.GoHome ( ) ; 
} 

} 
//浏览指定的Web地址 
private void button1_Click ( object sender , System.EventArgs e ) 
{ 
System.Object nullObject = 0 ; 
string str = "" ; 
System.Object nullObjStr = str ; 
Cursor.Current = Cursors.WaitCursor ; 
axWebBrowser1.Navigate ( textBox1.Text , ref nullObject , ref nullObjStr , ref nullObjStr , ref nullObjStr ) ; 
Cursor.Current = Cursors.Default ; 
} 
} 
总结 
至此一个功能相对完备的“浏览器”就算完成了,其实用Visual C#做“浏览器”的过程,也就是Visual C#中使用COM组件的过程。掌握了COM组件在Visual C#使用方法,就可以利用Visual C#编写出功能更强大,适应性更强的软件来,但编写的过程又十分的简单
基于AxWebBrowser开发的标签式浏览器源码 由于一时的头脑发热,花了两个晚上基于AxWebBrowser写了一个浏览器MyIE。现在用这个浏览器发的帖子,有点小市民的成就感,嘿嘿。源代码可以在本人的资源里下载到,这里简单总结如下:<br><br>1、VS2005自带的WebBrowser功能较少(网上资源也不多),AxWebBrowser控件暴露的事件更多些。比如打开新窗口的控制,WebBrowser貌似没有简单的方法来实现。<br><br>2、实现标签式界面,难点有:1)所有标签共用一个地址条、状态条、导航按钮,要切换上下文,要把界面状态封装起来,我封装到 BrowserData 类里,寄存在 TabPage.Tag 属性里;2)关闭一个Tab页时,默认会激活第一个Tab页,而不会回到上一个标签,我设计了一个标签栈(_pageStack)来管理;<br><br>3、实现了状态条,赞叹VS2005的 ToolStrip 功能强大,使用起来太方便了!感谢为我们铺路的工作者们!<br><br>4、实现了收藏夹功能,跟IE实时同步,其实也很简单,就是打开 Favorite 目录,遍历目录和子目录,解析链接文件;另一个难题是调出 IE 界面,例如“Internet 选项”“整理收藏夹”“添加到收藏夹”等;<br><br>5、集成了Google、百度搜索。<br><br>6、实现了输入框的自动完成,跟IE的效果完全一致。这里再次赞叹 ToolStrip 控件的强大~~<br><br>7、实现了地址条输入框历史记录管理、搜索关键字历史记录管理<br><br>8、花的时间很短,bug很少,不过代码没什么注释,读者就费点眼神吧,呵呵 :-) <br> 立即下载

相关推荐

直流电动机的建模仿真(1)他励,串励和并励电动机建模仿真

本文根据不同励磁方式的直流电动机的接线原理图,建立了相应的数学模型,然后根据与数学模型对应的等效电路以及模拟机械运动方程的等效电路,用Matlab/simulink中的SpecializedPower system库中的电路元件,建立了他励,并励和串励直流电动机的全等效电路仿真模型,经过与Matlab自带的直流电动机仿真模型比较以及仿真实例验证,所建立的仿真模型时完全正确的。

weixin_45670943的博客 7528

axWebBrowser使用总结

<br />1.添加axWebBrowser控件<br />   新建工程后,点"项目"-> "添加引用"-> "COM" -> 选中Microsoft.mshtml. 添加它<br />   切换到设计视图,在"工具箱"的某个选项卡上单击右键,选"添加/移除项..." . 再点"COM组件",选中"Microsoft Web浏览器",确定后, "Microsoft Web浏览器"控件终于出现在工具箱里了。

路在何方 1661

Flowable前端可视化配置动态审批人:告别硬编码,实现部门领导、项目经理自动分配

本文详细介绍了Flowable前端可视化配置动态审批人的全栈解决方案,通过表达式分配、监听器分配等动态审批人机制,实现从硬编码到智能分配的转变。文章提供了前端扩展bpmn-js设计器、后端动态解析实现方案及性能优化建议,帮助企业应对组织架构变动,提升审批流程的灵活性和效率。

weixin_30352645的博客 479

C#中的网页浏览器插件:AxWebBrowser ZT

最近在做一个程序中要求在WinForm中插一个浏览器的控件,在网上一找,找到了AxWebBrowser这个控件,它是一个COM的控件,所以先要往工具箱中添加这个控件,使得它能像其他可视化控件一样变得容易操作。添加完之后,你会在...

csdn_201601的博客 845

保姆级教程:在Ubuntu 22.04上搞定PX4 V1.14 + ROS2 Humble的HITL仿真(避坑实录)

本文提供在Ubuntu 22.04上配置PX4 V1.14与ROS2 Humble的HITL仿真环境的详细教程,涵盖环境准备、固件编译、QGroundControl配置、ROS2通信设置及联调测试。特别针对版本兼容性、Gazebo插件构建和MicroDDS配置等常见问题提供避坑指南,帮助开发者高效搭建无人机仿真系统。

weixin_30836759的博客 1016

GEO优化实战:用AnswerBit量化AI搜索可见度与品牌监控体系

生成式引擎优化(GEO)正取代传统SEO,成为品牌在AI搜索生态中获取可见度的关键。当用户习惯从“翻列表”转向“直接问AI”,品牌能否被生成式引擎识别、引用并正向推荐,直接决定了其在用户决策链条中的存在感。AI搜索可见度因此从模糊概念演变为可度量的运营指标,涵盖提及率、引文率、情感分与回源质量等维度。腾讯AnswerBit作为答案侧分析工具,帮助运营者拆解AI回复中的品牌语境与引用来源,让优化动作有据可循。从内容结构化改造、品牌实体建设到第三方权威背书,GEO要求团队建立“度量-优化-再度量”的闭环。文章结

weixin_31100517的博客 163

记录一个有关AxWebBrowser的诡异问题及解决方案。

在用vb.net开发软件的过程中,需要将单位的OA作为软件的一部分提供给用户。 这其中使用到了AxWebBrowser 编程环境 vs 2010 在开发的过程中发现一旦软件中的AxWebBrowser打开网页,如需要新开窗口,将自动打开ie,新建一个窗口。 AxWebBrowser的NewWindow3事件没有响应到。 开始怀疑不支持,于是另建一个干净的工程, 使用AxWebBrows

ruhong的专栏 1041

别再死记硬背窗函数公式了!用MATLAB实战汉宁窗FIR滤波器,从频谱图看懂‘主瓣’和‘旁瓣’

本文通过MATLAB实战演示汉宁窗FIR滤波器的设计过程,帮助读者从频谱图直观理解主瓣与旁瓣的特性。文章详细对比了矩形窗与汉宁窗的频谱差异,并提供了高通滤波器设计的完整代码示例,适用于数字信号处理学习和工程应用。

weixin_30555125的博客 496

如何在.net2003(C#)中引入AxWebBrowser控件.

经过反复摸索,终于搞清楚了把AxWebBrowser添加到工程里:1,新建工程后,点"项目"-> "添加引用"-> "COM" -> 选中Microsofr.mshtml. 添加它.2,切换到设计视图,在"工具箱"的某个选项卡上单击右键,选"添加/移除项..." . 再点"COM组件",选中"Microsoft Web浏览器",确定后, "Microsoft Web浏览器"控件终于出现在工

1356

CocosCreator视频播放黑屏?手把手教你封装VideoPlayer组件解决Web环境问题

本文针对Cocos Creator在Web环境下视频播放黑屏等常见问题,提供了一套工程化的VideoPlayer组件封装解决方案。文章深入剖析了浏览器自动播放策略、DOM样式隔离等核心挑战,并手把手教你实现一个健壮的管理器,涵盖兼容性处理、性能优化与内存管理,确保视频播放稳定流畅。

plum99的博客 609

非华为电脑与MatePad Pro多屏协同实战:从安装管家到攻克连接难题

本文详细介绍了在非华为电脑上安装华为电脑管家并实现与MatePad Pro多屏协同的完整指南。从安装步骤、常见连接失败解决方案到华为账号绑定技巧,提供了实用的操作方法和硬件优化建议,帮助用户攻克连接难题,提升多屏协同的稳定性和流畅度。

weixin_30263073的博客 248

在.net2003(C#)中引入AxWebBrowser控件.

经过反复摸索,终于搞清楚了把AxWebBrowser添加到工程里:1,新建工程后,点"项目"-> "添加引用"-> "COM" -> 选中Microsofr.mshtml. 添加它.2,切换到设计视图,在"工具箱"的某个选项卡上单击右键,选"添加/移除项..." . 再点"COM组件",选中"Microsoft Web浏览器",确定后, "Microsoft Web浏览器"控件终于出现在工

1618

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

C#查找指定窗口的子窗口的句柄

用axWebBrowser加载HTML网页时,真正显示内容的窗体并不是axWebBrowser,而是其子窗口的子窗口一个名为Internet Explorer_Server的类。从spy++可知:   公司需要在网页上进行手写,需要对Internet Explorer_Server进行操作,而通过axWebBrowser的Handle不能直接操作Internet Explorer_Serve...

weixin_34067102的博客 2916

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Microsoft Web Browser Automation using C#

codeproject的一篇文章,没有用webbrowser,而是直接使用axWebBrowser。http://www.codeproject.com/KB/cs/mshtml_automation.aspx?fid=26186&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2208064 文章中介绍了aximp的含义:

sclxf的专栏 1318

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

自动执行html里的javascript

自动执行html里的jsusingmshtml;IHTMLDocument2 HTMLDocument =(IHTMLDocument2) axWebBrowser1.Document;mshtml.IHTMLWindow2 win = HTMLDocument.parentWindow;string strScript = "onsubmit(3)";win.ex...

weixin_30673611的博客 86

如何打造标签式IE浏览器 (共享源码)

如何打造标签式IE浏览器(C#)                              电子科技大学软件学院03级02班 周银辉1,看看效果2,关于Browser控件        如果您用的IDE是VisualStudio 2005, 那么您会发现,上面有个WebBrowser控件,请 不要 使用该控件来开发这个浏览器(原因是它缺少了很多参数,将使您的工作在中途陷入困境)      

zhouyinhui的专栏 618

c#中用axWebBrowser中提交表单,或点击某个对象

dddd.htm -----------------------------------------------------------------------------------form1.csusing System;using System.Drawing;using System.Collections;using System.ComponentModel;using Syste

快乐的戏子 3152

在axWebBrowser内打开外链的Web页面

最近一个项目需要用到axWebBrowser控件,而axWebBrowser加载的页面中,有一个版块是Iframe框架加载其他站点的页面,而这个站点的所有链接都是target='_black'那种,所以就导致了每次点击这个iframe的链接时,都是新开一个IE浏览器打开页面,这明显不符合项目的要求啊!郁闷了~~~,在网上查了半天的资料,有关axWebBrowser控件的资料很少,更不用说在axWe

Dailen_Liao的专栏 2389

C# 网页放大缩小(WebBrowser && AxWebBrowser)

Net / WebBrowser var HTMLDocument = webBrowser1.Document; HTMLDocument.Body.Style = "ZOOM:0.5"; // 缩小

芳华如梦 8277

C#中在AxWebBrowser控件注入JS脚本的方法

/// <summary> /// 窗体加载 /// </summary> private void JS_Load(object sender, EventArgs e) { this.axWebBrowser1.Navigate("www.baidu.co...

ddufftimz66781829的博客 243

高分求HttpWebRequest使用axWebBrowser的session 和cookier的解决办法

本人需要做一个winform程序,语言是C#,目的是想用axWebBrowser控件来实现登陆,这样就可以不用自动分析一些网站的验证码。然后根据axWebBrowser登陆后产生的session 和 cookier 来附在HttpWebRequest的CookieContainer上。这样以后就可以分析数据流来取自己想要的内容,而不需axWebBrowser这个极耗资源的控件。哪位大侠快帮我啊,这

nico_angel的专栏 1394

AxWebBrowser禁止脚本(js)关闭窗口

在用AxWebBrowse制作自定义浏览器时需要处理一下,脚本关闭窗口的事件,不然它默认的会关闭整个软件 private void axWebBrowser_WindowClosing(object sender, AxSHDocVw.DWebBrowserEvents2_WindowClosingEvent e) { e.cancel = true;//

栖云山 1056
上一篇: 让你的电脑不安framework也能运行.net程序
下一篇: 验证码代码
许威威
博客等级 码龄17年 41粉丝 26原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值