C# 仅在下载请求时在CefSharp中格式化弹出窗口
我想在用户在CEFSharp中下载文件时创建一个特定的弹出窗口,我正在使用ILifeSpanHandler中的OnBeforePopup,但我无法检测弹出窗口是如何被调用的,例如,从链接或作为文件下载 有没有办法为不同类型的呼叫定制弹出窗口 这是我正在使用的代码C# 仅在下载请求时在CefSharp中格式化弹出窗口,c#,.net,chromium-embedded,cefsharp,C#,.net,Chromium Embedded,Cefsharp,我想在用户在CEFSharp中下载文件时创建一个特定的弹出窗口,我正在使用ILifeSpanHandler中的OnBeforePopup,但我无法检测弹出窗口是如何被调用的,例如,从链接或作为文件下载 有没有办法为不同类型的呼叫定制弹出窗口 这是我正在使用的代码 bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, stri
bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
{
// Set newBrowser to null unless your attempting to host the popup in a new instance of ChromiumWebBrowser
// This should only be used in WPF/OffScreen
newBrowser = null;
// Hosting the popup in your own control/window
// Use IWindowInfo.SetAsChild to specify the parent handle
// NOTE: Window resize not yet handled - you need to get the
// IBrowserHost from the newly created IBrowser instance that represents the popup
// Then subscribe to window resize notifications and call NotifyMoveOrResizeStarted().
// Also any chances in width/height you need to call SetWindowPos on the browsers HWND
// Use NativeMethodWrapper.SetWindowPosition to achieve this - you can get the HWND using
// IBrowserHost method
var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;
chromiumWebBrowser.Invoke(new Action(() =>
{
var owner = chromiumWebBrowser.FindForm();
var popup = new DownloadingPopup();
popup.CreateControl();
owner.AddOwnedForm(popup);
Control[] lbFileName = popup.Controls.Find("lbFileName", true);
Label lbfilename = (Label)lbFileName[0];
lbfilename.Text = "Downloading";
lbfilename.Font = new System.Drawing.Font("Oswald", 14);
var control = new Control();
control.Dock = DockStyle.Fill;
control.CreateControl();
popup.Controls.Add(control);
popup.Show();
var rect = control.ClientRectangle;
windowInfo.SetAsChild(control.Handle, rect.Left, rect.Top, rect.Right, rect.Bottom);
}));
return false; //Return true to cancel the popup creation
}
实现
IDownloadHandler
?实现IDownloadHandler
?