private void guna2Button4_Click(object sender, EventArgs e) { webView1.CoreWebView2.NavigateToString(gameHTML.GenerateArcadePage()); //guna2Button4.ForeColor = Color.White; //guna2Button5.ForeColor = Color.FromArgb(154, 157, 160); //guna2Button7.ForeColor = Color.FromArgb(154, 157, 160); webView1.Show(); }
private async void InitializeAsync() { GameHTML gameHTML = new GameHTML(); var creatonProperties = new Microsoft.Web.WebView2.WinForms.CoreWebView2CreationProperties(); creatonProperties.BrowserExecutableFolder = Application.StartupPath + "\\WebView2"; webView1.CreationProperties = creatonProperties; await webView1.EnsureCoreWebView2Async(null); webView1.CoreWebView2.SetVirtualHostNameToFolderMapping("images", Application.StartupPath + "\\images", Microsoft.Web.WebView2.Core.CoreWebView2HostResourceAccessKind.Allow); webView1.NavigationCompleted += async(sender, e) => { if (!File.Exists(Application.StartupPath + "/images/avatar.png")) { (new WebClient()).DownloadFile("https://benevis.com/wp-content/uploads/2019/09/default-avatar-1.jpg", Application.StartupPath + "/images/avatar.png"); } if (Properties.Settings.Default.User == null) { Properties.Settings.Default.User = new User { Username = "******" } } ; await webView1.ExecuteScriptAsync($"document.getElementById('username').innerHTML = '{ Properties.Settings.Default.User.Username }';"); await webView1.ExecuteScriptAsync($"document.getElementById('username').value = '{ Properties.Settings.Default.User.Username }';"); await webView1.ExecuteScriptAsync($"document.getElementById('userimage').src = '{ "http://images/avatar.png" }';"); await webView1.ExecuteScriptAsync($"document.getElementById('parallelTransfers').value = '{ Properties.Settings.Default.ParallelTransfers }';"); }; webView1.CoreWebView2.NavigateToString(gameHTML.GenerateArcadePage()); webView1.CoreWebView2.AddHostObjectToScript("arcade", new Arcade()); webView1.CoreWebView2.AddHostObjectToScript("eventForwarder", new EventForwarder(this.Handle)); webView1.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false; webView1.CoreWebView2.Settings.AreDevToolsEnabled = false; }
public async void ArcadePage() { MainWindow mainWindow = Application.OpenForms["MainWindow"] as MainWindow; mainWindow.webView1.CoreWebView2.NavigateToString(gameHTML.GenerateArcadePage()); }