【发布时间】:2021-02-12 05:28:37
【问题描述】:
我尝试了很多,但无法成功:(。 我想在同一个主窗口而不是新窗口中打开第二个窗口。
我尝试了以下但没有运气,也许我做错了什么,因为我不擅长编码:(
https://github.com/cefsharp/CefSharp/issues/600
https://github.com/cefsharp/CefSharp/issues/688
https://www.codeproject.com/Articles/1194609/Capturing-a-pop-up-window-using-LifeSpanHandler-an
您能帮我找到解决方案,因此无论您在任何网页上单击什么按钮,它都只在窗口中打开
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.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;
using System.Diagnostics;
using Microsoft.Win32;
namespace Nysus
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
ChromiumWebBrowser chrome;
private void Form1_Load(object sender, EventArgs e)
{
CefSettings settings = new CefSettings();
//Initialize
Cef.EnableHighDPISupport();
Cef.Initialize(settings);
chrome = new ChromiumWebBrowser("http://www.google.com");
this.pContainer.Controls.Add(chrome);
chrome.Dock = DockStyle.Fill;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
if (chrome.CanGoForward)
chrome.Forward();
if (chrome.CanGoBack)
chrome.Back();
}
private void Form1_FormClosing_1(object sender, FormClosingEventArgs e)
{
Cef.Shutdown();
}
public bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
{
browser.MainFrame.LoadUrl(targetUrl);
newBrowser = null;
return true;
}
}
}
【问题讨论】:
标签: c# visual-studio winforms cefsharp