WebBrowser 简单操作

Form 代码

    public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char))
{
webBrowser1.Navigate(textBox1.Text);
}
} private void Form1_Load(object sender, EventArgs e)
{
buttonBack.Enabled = false;
buttonForward.Enabled = false;
buttonStop.Enabled = false; this.webBrowser1.CanGoBackChanged += (s, k) => { if (webBrowser1.CanGoBack) buttonBack.Enabled = true; else buttonBack.Enabled = false; };
this.webBrowser1.CanGoForwardChanged += (s, k) => { if (webBrowser1.CanGoForward) buttonForward.Enabled = true; else buttonForward.Enabled = false; };
this.webBrowser1.DocumentTitleChanged += (s, k) => { this.Text = webBrowser1.DocumentTitle.ToString(); };
} private void buttonBack_Click(object sender, EventArgs e)
{
webBrowser1.GoBack();
textBox1.Text = webBrowser1.Url.ToString();
} private void buttonForward_Click(object sender, EventArgs e)
{
webBrowser1.GoForward();
textBox1.Text = webBrowser1.Url.ToString();
} private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
this.Text = webBrowser1.DocumentTitle.ToString();
textBox1.Text = webBrowser1.Url.ToString();
} private void buttonStop_Click(object sender, EventArgs e)
{
webBrowser1.Stop();
} private void buttonHome_Click(object sender, EventArgs e)
{
webBrowser1.GoHome();
textBox1.Text = webBrowser1.Url == null ? "" : webBrowser1.Url.ToString();
} private void buttonRefresh_Click(object sender, EventArgs e)
{
webBrowser1.Refresh();
} private void buttonSubmit_Click(object sender, EventArgs e)
{
webBrowser1.Navigate(textBox1.Text);
} private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
buttonStop.Enabled = true;
} private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
textBox2.Text = webBrowser1.DocumentText;
buttonStop.Enabled = false;
if (webBrowser1.CanGoBack)
buttonBack.Enabled = true;
else
buttonBack.Enabled = false; if (webBrowser1.CanGoForward)
buttonForward.Enabled = true;
else
buttonForward.Enabled = false;
} private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Print();
}
}

Designer 代码

  partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows Form Designer generated code /// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.buttonSubmit = new System.Windows.Forms.Button();
this.buttonRefresh = new System.Windows.Forms.Button();
this.buttonHome = new System.Windows.Forms.Button();
this.buttonStop = new System.Windows.Forms.Button();
this.buttonForward = new System.Windows.Forms.Button();
this.buttonBack = new System.Windows.Forms.Button();
this.webBrowser1 = new System.Windows.Forms.WebBrowser();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(, );
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(, );
this.textBox1.TabIndex = ;
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
//
// buttonSubmit
//
this.buttonSubmit.Location = new System.Drawing.Point(, );
this.buttonSubmit.Name = "buttonSubmit";
this.buttonSubmit.Size = new System.Drawing.Size(, );
this.buttonSubmit.TabIndex = ;
this.buttonSubmit.Text = "Submit";
this.buttonSubmit.UseVisualStyleBackColor = true;
this.buttonSubmit.Click += new System.EventHandler(this.buttonSubmit_Click);
//
// buttonRefresh
//
this.buttonRefresh.Location = new System.Drawing.Point(, );
this.buttonRefresh.Name = "buttonRefresh";
this.buttonRefresh.Size = new System.Drawing.Size(, );
this.buttonRefresh.TabIndex = ;
this.buttonRefresh.Text = "Refresh";
this.buttonRefresh.UseVisualStyleBackColor = true;
this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click);
//
// buttonHome
//
this.buttonHome.Location = new System.Drawing.Point(, );
this.buttonHome.Name = "buttonHome";
this.buttonHome.Size = new System.Drawing.Size(, );
this.buttonHome.TabIndex = ;
this.buttonHome.Text = "Home";
this.buttonHome.UseVisualStyleBackColor = true;
this.buttonHome.Click += new System.EventHandler(this.buttonHome_Click);
//
// buttonStop
//
this.buttonStop.Location = new System.Drawing.Point(, );
this.buttonStop.Name = "buttonStop";
this.buttonStop.Size = new System.Drawing.Size(, );
this.buttonStop.TabIndex = ;
this.buttonStop.Text = "Stop";
this.buttonStop.UseVisualStyleBackColor = true;
this.buttonStop.Click += new System.EventHandler(this.buttonStop_Click);
//
// buttonForward
//
this.buttonForward.Location = new System.Drawing.Point(, );
this.buttonForward.Name = "buttonForward";
this.buttonForward.Size = new System.Drawing.Size(, );
this.buttonForward.TabIndex = ;
this.buttonForward.Text = "Forward";
this.buttonForward.UseVisualStyleBackColor = true;
this.buttonForward.Click += new System.EventHandler(this.buttonForward_Click);
//
// buttonBack
//
this.buttonBack.Location = new System.Drawing.Point(, );
this.buttonBack.Name = "buttonBack";
this.buttonBack.Size = new System.Drawing.Size(, );
this.buttonBack.TabIndex = ;
this.buttonBack.Text = "Back";
this.buttonBack.UseVisualStyleBackColor = true;
this.buttonBack.Click += new System.EventHandler(this.buttonBack_Click);
//
// webBrowser1
//
this.webBrowser1.Location = new System.Drawing.Point(, );
this.webBrowser1.MinimumSize = new System.Drawing.Size(, );
this.webBrowser1.Name = "webBrowser1";
this.webBrowser1.Size = new System.Drawing.Size(, );
this.webBrowser1.TabIndex = ;
this.webBrowser1.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowser1_DocumentCompleted);
this.webBrowser1.Navigated += new System.Windows.Forms.WebBrowserNavigatedEventHandler(this.webBrowser1_Navigated);
this.webBrowser1.Navigating += new System.Windows.Forms.WebBrowserNavigatingEventHandler(this.webBrowser1_Navigating);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(, );
this.textBox2.Multiline = true;
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(, );
this.textBox2.TabIndex = ;
//
// button1
//
this.button1.Location = new System.Drawing.Point(, );
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(, );
this.button1.TabIndex = ;
this.button1.Text = "Print";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.textBox2);
this.Controls.Add(this.webBrowser1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.buttonSubmit);
this.Controls.Add(this.button1);
this.Controls.Add(this.buttonRefresh);
this.Controls.Add(this.buttonHome);
this.Controls.Add(this.buttonStop);
this.Controls.Add(this.buttonForward);
this.Controls.Add(this.buttonBack);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button buttonSubmit;
private System.Windows.Forms.Button buttonRefresh;
private System.Windows.Forms.Button buttonHome;
private System.Windows.Forms.Button buttonStop;
private System.Windows.Forms.Button buttonForward;
private System.Windows.Forms.Button buttonBack;
private System.Windows.Forms.WebBrowser webBrowser1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
}
}

通过流 读取页面源代码

            WebClient client = new WebClient();
Stream str= client.OpenRead("http://www.baidu.com");
StreamReader sr = new StreamReader(str); string line;
while ((line=sr.ReadLine())!=null)
{
listBox1.Items.Add(line);
}
str.Close();

打印方法

       webBrowser1.Print();

C# WebBrowser使用 网络(二)的更多相关文章

  1. C# 通过扩展WebBrowser捕获网络连接错误信息

    想捕获WebBrowser连接指定网站过程中发生的错误信息,包括网络无法连接.404找不到网页等等错误!经过网上的搜集,找到了以下解决方案,该解决方案不会在网站连接前发出多余的测试请求. 向Webbr ...

  2. 办公室网络二三事 - chunyu

    开始的时候,我们办公室拉了两条家庭百兆宽带,两条宽带分别接到路由器的wan1/wan2口上,我们愉快的工作愉快的上网. 后来,再拉了一条十兆企业专线,接到了路由器的wan3口上面,配了一些静态路由,希 ...

  3. 机器学习:深入理解LSTM网络 (二)

    之前我们介绍了RNN 网络结构以及其所遇到的问题,RNN 结构对于关联度太长的时序问题可能无法处理, 简单来说,RNN对于太久远的信息不能有效地储存,为了解决这个问题,有人提出了LSTM的网络结构,L ...

  4. Linux的VMWare下Centos7的三种网络配置过程(网络二)

    Linux之VMWare下Centos7的三种网络配置过程 环境:虚拟软件:VMWare 14.0客户机:windows 10虚拟机:centos 7 VMware三种网络连接方式 Bridge(桥接 ...

  5. 【卷二】网络二—TCP服务器与客户端

    经过上回简单地介绍,大家对服务器多少应该清楚一些了吧!还记得TCP: (Transmission Control Protocol) 传输控制协议? 还记得IP: (Internet Protocol ...

  6. 网络二十四题 之 P2756 飞行员配对方案问题

    题目背景 第二次世界大战时期.. 题目描述 英国皇家空军从沦陷国征募了大量外籍飞行员.由皇家空军派出的每一架飞机都需要配备在航行技能和语言上能互相配合的2 名飞行员,其中1 名是英国飞行员,另1名是外 ...

  7. socket网络(二)

    作用域 python/js语言中,无块级作用域 if 1 == 1: name = 'alex' print(name) python中以函数为作用域 def func(): name = 'alex ...

  8. 【CentOS】虚拟机网络配置与远程登录

    ////////////////////////////////////11月16日更新////////////////////////////////////////////////////// 一 ...

  9. 【网络】VPN

    VPN: 来自百度百科 虚拟专用网络的功能是:在公用网络上建立专用网络,进行加密通讯.在企业网络中有广泛应用.VPN网关通过对数据包的加密和数据包目标地址的转换实现远程访问.VPN有多种分类方式,主要 ...

随机推荐

  1. Docker 安装 Apache

    查找Docker Hub上的httpd镜像 apache$ docker search httpd 拉取官方的镜像 docker pull httpd 使用apache镜像 创建目录apache,用于 ...

  2. 【Python】【demo实验35】【基础实验】【排序】【选择法排序】

    原题: 使用选择法对10个数字排序: 即取10个数中最小的放在第一个位置,再取剩下9个中最小的放在第二个位置... 我的源码: #!/usr/bin/python # encoding=utf-8 # ...

  3. DDL数据库对象管理

    DDL数据库对象管理 约束的分类: 主键约束:primary key 要求主键列数据唯一,并且不允许为空. 外键约束:foreign key 用于在两表之间建立关系,需要指定引用主表的哪一列. 检查约 ...

  4. 在Linux环境下的对启动服务进行停止或在运行

    下面我以elasticsearch服务为例进行: 第一种: 1.前台运行: 运行结果 2.ctrl+c停止运行   第二种:后端运行 1.后端运行的命令./elasticsearch -d 这种启动后 ...

  5. Ural 1238 Folding 题解

    目录 Ural 1238 Folding 题解 题意 题解 程序 Ural 1238 Folding 题解 题意 定义折叠.展开为: 单个大写英文字母是一个折叠的串,把它展开后是它本身. 如果\(S\ ...

  6. 洛谷 P2746 [USACO5.3]校园网Network of Schools

    题目描述 一些学校连入一个电脑网络.那些学校已订立了协议:每个学校都会给其它的一些学校分发软件(称作“接受学校”).注意即使 B 在 A 学校的分发列表中, A 也不一定在 B 学校的列表中. 你要写 ...

  7. 玩linux笔记——持续更新

    说在最前面 centos 是基于redhat linux,所以最好的教程在红帽官网 https://access.redhat.com/documentation/en-us/red_hat_ente ...

  8. k8s-搭建 EFK 日志系统

    搭建 EFK 日志系统 大家介绍了 Kubernetes 集群中的几种日志收集方案,Kubernetes 中比较流行的日志收集解决方案是 Elasticsearch.Fluentd 和 Kibana( ...

  9. ArrayList插入1000w条数据的时间比较分析

    一分钟系列: 读懂GC日志 ArrayList插入1000w条数据之后,我怀疑了jvm... Java JIT性能调优 Java性能优化指南系列(三):理解JIT编译器 准备:调试程序加入VM Opt ...

  10. caffe prototxt分析

    测试用prototxt name: "CIFAR10_quick"layer { name: "data" type: "MemoryData&quo ...