1.安装CefSharp

2.GetMac()获取用户mac地址方法

3.根据错误提示新建CEFKeyBoardHander.cs

form1.cs

using CefSharp;
using CefSharp.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace WindowsFormsApp
{
public partial class Form1 : Form
{
private ChromiumWebBrowser browser; private string mac { get; set; } public Form1()
{
GetMac();
InitializeComponent();
InitBrowser();
} public void GetMac() {
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection nics = mc.GetInstances();
foreach (ManagementObject nic in nics)
{
if (Convert.ToBoolean(nic["ipEnabled"]) == true)
{
mac = nic["MacAddress"].ToString();//Mac地址
//string ip = (nic["IPAddress"] as String[])[0];//IP地址
//string ipsubnet = (nic["IPSubnet"] as String[])[0];//子网掩码
//string ipgateway = (nic["DefaultIPGateway"] as String[])[0];//默认网关
}
}
} public void InitBrowser()
{
//设置语言环境 以上这段代码一定要在new ChromiumWebBrowser之前调用
var setting = new CefSettings(); setting.CefCommandLineArgs.Add("--disable-web-security", "1");//关闭同源策略,允许跨域 setting.Locale = "zh-CN";
//缓存路径
setting.CachePath = System.AppDomain.CurrentDomain.BaseDirectory + "BrowserCache";
//浏览器引擎的语言
setting.AcceptLanguageList = "zh-CN,zh;q=0.8";
setting.LocalesDirPath = System.AppDomain.CurrentDomain.BaseDirectory + "LocaleDir";
//日志文件
setting.LogFile = System.AppDomain.CurrentDomain.BaseDirectory + "LogData"; setting.CefCommandLineArgs.Add("mute-audio", "true"); setting.PersistSessionCookies = true; setting.UserDataPath = System.AppDomain.CurrentDomain.BaseDirectory + "UserData";
Cef.Initialize(setting); // string url = AppDomain.CurrentDomain.BaseDirectory + @"../../html/index.html";
// url = url.Replace("\\", "/").Replace(" ", "%20"); mac = mac.Replace(":", "-"); string url = @"http://111.111.111.111:9000/111.php/index/login/mac/"+mac; // Cef.Initialize(new CefSettings());
browser = new ChromiumWebBrowser(url);
Font font = new Font("微软雅黑", 10.5f); browser.Font = font;
browser.Dock = DockStyle.Fill; browser.KeyboardHandler = new CEFKeyBoardHander(); browser.LoadingStateChanged += new EventHandler<LoadingStateChangedEventArgs>(LoadingStateChangeds);
// 加载完成后 , 执行操作
browser.FrameLoadEnd += new EventHandler<FrameLoadEndEventArgs>(FrameEndFunc); // 加载完成后 , 执行操作
browser.FrameLoadStart += new EventHandler<FrameLoadStartEventArgs>(FrameLoadStart); this.Controls.Add(browser);
} private void LoadingStateChangeds(object sender, LoadingStateChangedEventArgs e)
{
// throw new NotImplementedException();
} private void FrameLoadStart(object sender, FrameLoadStartEventArgs e)
{
//throw new NotImplementedException();
} private void FrameEndFunc(object sender, FrameLoadEndEventArgs e)
{
// throw new NotImplementedException();
} }
}

CEFKeyBoardHander.cs

using CefSharp;

namespace WindowsFormsApp
{
internal class CEFKeyBoardHander : IKeyboardHandler
{
public bool OnKeyEvent(IWebBrowser chromiumWebBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey)
{
//throw new System.NotImplementedException();
return false;
} public bool OnPreKeyEvent(IWebBrowser chromiumWebBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut)
{
return false;
}
}
}

---------------------------

最新文章

  1. Python 修饰符
  2. 1117 新冲刺 day1
  3. android Button 切换背景,实现动态按钮和按钮颜色渐变
  4. [04] SQL语句优化之索引
  5. 转:CString::GetLength()获得字节数的正确方法
  6. hadoop下载
  7. STM32驱动OV7725摄像头颜色识别
  8. js实现一个简单钟表动画(javascript+html5 canvas)
  9. AndroidVerifyBoot
  10. hadoop的节点间的通信
  11. 安装Visual Studio 语言包时出现windows 程序兼容模式已打开.请将其关闭
  12. Python 3.x 格式化输出字符串 % &amp; format 笔记
  13. [转]MyEclipse8.5破解方法
  14. (转)看穿机器学习(W-GAN模型)的黑箱
  15. vmware中装的ubuntu上不了网
  16. ps命令各个内容信息详解
  17. PHP设计模式系列 - 观察者模式
  18. php实现注册审核功能
  19. java的初始化(编程思想)
  20. StringUtils 中 isEmpty 和 isBlank 的区别

热门文章

  1. 电气原理图制图相关GB标准
  2. Appium常见属性和命令
  3. Windows Service调试方法小结
  4. MSF内网信息收集
  5. [转载]Net分布式系统之四:RabbitMQ消息队列应用
  6. Mac技术服务, 感谢 点赞打赏
  7. Visualization: Pie Chart(可视化:饼图)
  8. requests学习笔记02
  9. HCIP-ICT实战进阶06-BGP基础
  10. 华为&amp;思科设备默认的路由协议优先级