Chromuiumwebbrowser打开空白形式为什么?

发布于 2025-01-21 17:16:26 字数 272 浏览 2 评论 0原文

我创建了一个项目,并在其中添加了nuget的cefsharp.winforms。

我给了一个地址,铬植物打开了它。当我围绕此地址导航时,我单击了下载链接。没问题,文件已下载。但是,一个空的形式打开了。

什么是空形式,为什么它打开和如何从代码中关闭它?

空白形式出现链接

I created a project and added CefSharp.WinForms from nuget in it.

I gave an address and ChromiumWebBrowser opened it. While I was navigating around this address, I clicked a download link. No problem, the file is downloaded. but with that an empty form opens.

what is this empty form, why is it opening and how can i close it from the code?

Blank Form Comes Link

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑凤梨 2025-01-28 17:16:26

如果您单击的链接打开了一个弹出窗口,则可以预期一个空白窗口。您可以隐藏窗口,直到下载完成,然后将其关闭。以下代码将所有文件保存到temp文件夹。您可以将文件夹更改为用户配置文件中的路径,也可以将文件夹更改为“ usefolder呼叫” askuser。

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWindowVisible(IntPtr hWnd);

[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

var tempPath = System.IO.Path.GetTempPath();

browser.DownloadHandler =
    Fluent.DownloadHandler.UseFolder(tempPath,
        (chromiumBrowser, browser, downloadItem, callback) =>
        {
            if (downloadItem.IsComplete || downloadItem.IsCancelled)
            {
                if (browser.IsPopup && !browser.HasDocument)
                {
                    browser.GetHost().CloseBrowser(true);
                }
            }
            //TODO: You may wish to customise this condition to better suite your
            //requirements. 
            else if(downloadItem.ReceivedBytes < 100)
            {
                var popupHwnd = browser.GetHost().GetWindowHandle();

                var visible = IsWindowVisible(popupHwnd);
                if(visible)
                {
                    const int SW_HIDE = 0;
                    ShowWindow(popupHwnd, SW_HIDE);
                }
            }
        });

If the link you clicked opened a popup then a blank window is expected. You can hide the window until the download is complete then close it. The following code saves all files to a temp folder. You can change the folder to a path within the users profile or instead of UseFolder call AskUser.

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWindowVisible(IntPtr hWnd);

[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

var tempPath = System.IO.Path.GetTempPath();

browser.DownloadHandler =
    Fluent.DownloadHandler.UseFolder(tempPath,
        (chromiumBrowser, browser, downloadItem, callback) =>
        {
            if (downloadItem.IsComplete || downloadItem.IsCancelled)
            {
                if (browser.IsPopup && !browser.HasDocument)
                {
                    browser.GetHost().CloseBrowser(true);
                }
            }
            //TODO: You may wish to customise this condition to better suite your
            //requirements. 
            else if(downloadItem.ReceivedBytes < 100)
            {
                var popupHwnd = browser.GetHost().GetWindowHandle();

                var visible = IsWindowVisible(popupHwnd);
                if(visible)
                {
                    const int SW_HIDE = 0;
                    ShowWindow(popupHwnd, SW_HIDE);
                }
            }
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文