Files
cms_thermo_active/Client2020/MainForm.cs
T
2020-10-23 16:23:59 +02:00

87 lines
2.4 KiB
C#

using CefSharp;
using CefSharp.WinForms;
using Client.Config;
using Client.Utils;
using Client2020.BrowserTools;
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;
namespace Client2020
{
public partial class MainForm : Form
{
ChromiumWebBrowser browser;
public MainForm()
{
InitializeComponent();
//Setup the Icon
if (Config.ClientConfig.IsSCM)
this.Icon = Properties.Resources.MAESTRO_ACTIVE_ICON;
//Start the browser
browser = new ChromiumWebBrowser(Config.ConnectionConfig.StartingUrl);
this.Controls.Add(browser);
//Setup the Object Custom
browser.JavascriptObjectRepository.Register(Constants.BROWSER_JS_OBJ_NAME, new BrowserJSObject(this), isAsync: false, options: BindingOptions.DefaultBinder);
//Setup the Handlers
browser.RenderProcessMessageHandler = new CMSRenderBrowser();
browser.MenuHandler = new CMSContextBrowser();
//Setu the NC behaviour
NcWindow.mainFrm = this;
NcWindow.StartStepFollowing(this.Handle);
}
public void keyPressedHandler(bool altPressed, bool ctrlPressed, bool shiftPressed, int key)
{
//Work only if is a Developer mode
if (Config.ClientConfig.DeveloperMode && altPressed)
{
if (key == (int)Keys.F5)
{
browser.Reload(true);
}
if (key == (int)Keys.F12)
browser.ShowDevTools();
if (key == (int)Keys.F10)
ShowPopup("chrome://gpu/");
if (key == (int)Keys.F11)
ShowPopup("chrome://version/");
}
}
//Show Chrome Window
private void ShowPopup(string url)
{
int w = 1600, h = 800;
Form frm = new Form();
frm.Controls.Add(new ChromiumWebBrowser(url));
frm.Height = h;
frm.Width = w;
frm.StartPosition = FormStartPosition.CenterScreen;
frm.ShowDialog();
}
}
}