Skip to content

Instantly share code, notes, and snippets.

@AlexP11223
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexP11223/86791932adb64edeb81e to your computer and use it in GitHub Desktop.
Save AlexP11223/86791932adb64edeb81e to your computer and use it in GitHub Desktop.
using System;
using System.IO;
using System.Windows.Forms;
using Awesomium.Core;
using Awesomium.Windows.Forms;
namespace WindowsFormsApplication3
{
static class Program
{
public static readonly string AppDir = AppDomain.CurrentDomain.BaseDirectory;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string html = @"
<html><body>
<script>
function addMessage(message){
var ni = document.getElementById(""main"");
var newdiv = document.createElement('div');
newdiv.innerHTML = message;
ni.appendChild(newdiv);
};
</script>
<div id=""main""> <img src='file:///C:/Program%20Files/Common%20Files/microsoft%20shared/Stationery/Bears.jpg'></div>
</body></html>";
string htmlPath = AppDir + "1.html";
File.WriteAllText(htmlPath, html);
var form1 = new Form() { Width = 600, Height = 500, Text = "LoadHTML" };
var webControl1 = new WebControl() { Parent = form1, Dock = DockStyle.Fill };
webControl1.LoadingFrameComplete += WebControlOnLoadingFrameComplete;
var form2 = new Form() { Width = 600, Height = 500, Text = "Source" };
var webControl2 = new WebControl() { Parent = form2, Dock = DockStyle.Fill };
webControl2.LoadingFrameComplete += WebControlOnLoadingFrameComplete;
int i = 0;
WebCore.CreatedView += (sender, args) =>
{
switch (i)
{
case 0:
webControl1.LoadHTML(File.ReadAllText(htmlPath));
break;
case 1:
webControl2.Source = htmlPath.ToUri();
break;
}
i++;
};
form2.Show();
Application.Run(form1);
}
private static void WebControlOnLoadingFrameComplete(object sender, FrameEventArgs e)
{
var webControl = (WebControl) sender;
if (e.IsMainFrame)
{
webControl.ExecuteJavascript("addMessage('<img src=\\'file:///C:/Program%20Files/Common%20Files/microsoft%20shared/Stationery/Bears.jpg\\'>')");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment