-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormMain.cs
84 lines (71 loc) · 2.55 KB
/
FormMain.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.IO;
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 CefSharp;
using CefSharp.WinForms;
using System.Runtime.InteropServices;
namespace ZiZhuJi
{
public partial class FormMain : Form
{
public ChromiumWebBrowser chromeBrowser;
public FormMain()
{
InitializeComponent();
InitializeChromium();
CefSharpSettings.LegacyJavascriptBindingEnabled = true;
chromeBrowser.JavascriptObjectRepository.Register("cefCustomObject", new CefCustomObject(chromeBrowser, this), isAsync: true, options: BindingOptions.DefaultBinder);
}
private void FormMain_Load(object sender, EventArgs e)
{
}
public void InitializeChromium()
{
CefSettings settings = new CefSettings();
string page = string.Format(@"{0}\www\index.html", Application.StartupPath);
if (!File.Exists(page))
{
MessageBox.Show("Error The html file doesn't exists : " + page);
}
Cef.Initialize(settings);
chromeBrowser = new ChromiumWebBrowser(page);
this.Controls.Add(chromeBrowser);
chromeBrowser.Dock = DockStyle.Fill;
// Allow the use of local resources in the browser
BrowserSettings browserSettings = new BrowserSettings();
browserSettings.FileAccessFromFileUrls = CefState.Enabled;
browserSettings.UniversalAccessFromFileUrls = CefState.Enabled;
chromeBrowser.BrowserSettings = browserSettings;
}
public void FormMain_Closing(object sender, FormClosingEventArgs e)
{
Cef.Shutdown();
}
public void FormMain_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F12)
{
CefCustomObject cefCustomObject = new CefCustomObject(chromeBrowser, this);
cefCustomObject.showDevTools();
}
}
private void AddressTextBox_TextChanged(object sender, EventArgs e)
{
}
private void AddressTextBox_keyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
CefCustomObject cefCustomObject = new CefCustomObject(chromeBrowser, this);
cefCustomObject.loadPage(AddressTextBox.Text);
}
}
}
}