一、EO.Total程序包安装
1、EO.WebBrowser
2、EO.WebBrowser.WinForm
二、 Winform 布局
1、插入控件“Panel”
点击控件“Panel”
鼠标移动到Form界面,在想要添加的地方点击
找到属性Dock,选在Fill(填充form)
2、插入控件“WebControl”
点击控件”WebControl“
鼠标移动到Form界面,在想要添加的地方点击
找到属性Dock,选在Fill(填充form)
三、后台:显示网页(修改参数即可直接使用)
双击Form外框,添加如下代码
注:代理服务器部分请根据真是情况进行参数设置
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EO.Base;//ProxyInfo类型所需
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
EO.WebEngine.Engine engine1 = EO.WebEngine.Engine.Create("test");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;//令窗口最大化
#region 设置代理服务器(此处设置后启动就不需要输入代理的账号和密码)
string host = "***.*.**.***";//需修改
int port = 1234;//需修改
string username = "用户名";//需修改
string password = "密码";//需修改
ProxyInfo proxy = new ProxyInfo(ProxyType.HTTP, host, port, username, password);
engine1.Options.Proxy = proxy;
webView1.Engine = engine1;
#endregion
#region 加载页面
string url = "https://www.baidu.com/";
webView1.AcceptLanguage = "en";//设置界面语言
webView1.LoadUrlAndWait(url);//加载起始页
threadsleep(1000);//等待时间
webView1.EvalScript("document.location.reload();");//刷新页面
#endregion
}
public static void threadsleep(int li_time)
{
Application.DoEvents();
EO.WebBrowser.WebView.DoEvents();
System.Threading.Thread.Sleep(li_time);
}
}
}
四、扩展
1、类型
(1)EO.Base.ProxyInfo
注:函数调用,可以有三种类型,可带账号密码,也可不带。
namespace EO.Base
{
public class ProxyInfo
{
public ProxyInfo(ProxyType type, string host, int port);
public ProxyInfo(ProxyType type, string host, int port, string username, string password);
public ProxyInfo(ProxyType type, string host, int port, string username, string password, string bypass);
public static ProxyInfo Direct { get; }
public ProxyType Type { get; }
public string HostName { get; }
public int Port { get; }
public string UserName { get; }
public string Password { get; }
public string Bypass { get; }
public bool UseDirect { get; }
public ProxyInfo Clone();
public override string ToString();
}
}