gpt4 book ai didi

c# - CefWebBrowser 不显示

转载 作者:太空狗 更新时间:2023-10-29 17:46:41 25 4
gpt4 key购买 nike

解决方案:

此问题是由于未在 Program.cs 中加载 CefRuntime 引起的。只需将示例文件中的所有代码复制到您的 Program.cs。

然后,如果您的 CefWebBrowser 卡住并且有“旋转等待鼠标光标”,则设置 SingleProcess = true。

原因是如果浏览器是从一个可识别的二级进程调用的,整个进程会被阻塞,直到进程结束。


问题:

有人有在 WinForm 中使用 CEF(Chromium 嵌入式框架)的经验吗?

这个组件折磨了我一整天。我无法让它工作。它只是没有出现。

所以我的问题是:如何在 WinForm 应用程序中使用 CEF?

我确实查看了论坛,但令人惊讶的是没有人问这个问题。看来我是唯一一个不知道如何使用它的笨蛋。

public partial class Form1 : Form
{
private CefWebBrowser cefwbShell = null;
//private readonly SynchronizationContext _pUIThread;

private void Form1_Load(object sender, EventArgs e)
{
cefwbShell.Visible = true;
cefwbShell = new CefWebBrowser { StartUrl = "http://example.com" };
cefwbShell.Parent = this;
cefwbShell.Dock = DockStyle.Fill;
cefwbShell.BringToFront();
cefwbShell.Show();
}
}

更新:

我正在尝试使用 Xilium.CefGlue。在我复制了正确版本的发布 dll (991) 之后,我得到一个异常:

InvalidOperationException was unhandlled by user code 
Failed to create browser.

来源:Xilium.CefGlue

堆栈跟踪:

at Xilium.CefGlue.CefBrowserHost.CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, String url) in C:\Winston\Knowledge\Projects\xilium-xilium.cefglue-61551ec98ad8\xilium-xilium.cefglue-61551ec98ad8\CefGlue\Classes.Proxies\CefBrowserHost.cs:line 37
at Xilium.CefGlue.WindowsForms.CefWebBrowser.OnHandleCreated(EventArgs e) in C:\Winston\Knowledge\Projects\xilium-xilium.cefglue-61551ec98ad8\xilium-xilium.cefglue-61551ec98ad8\CefGlue.WindowsForms\CefWebBrowser.cs:line 71
at System.Windows.Forms.Control.WmCreate(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)

谁能帮帮我?

更新 2:

private void Create()
{
var page = new TabPage("New Tab");
page.Padding = new Padding(0, 0, 0, 0);

var browser = new CefWebBrowser();
browser.StartUrl = startUrl;
browser.Dock = DockStyle.Fill;
browser.TitleChanged += (s, e) =>
{
BeginInvoke(new Action(() =>
{
var title = browser.Title;
if (tabControl.SelectedTab == page)
{
Text = browser.Title + " - " + _mainTitle;
}
page.ToolTipText = title;
if (title.Length > 18)
{
title = title.Substring(0, 18) + "...";
}
page.Text = title;
}));
};
browser.AddressChanged += (s, e) =>
{
BeginInvoke(new Action(() =>
{
addressTextBox.Text = browser.Address;
}));
};
browser.StatusMessage += (s, e) =>
{
BeginInvoke(new Action(() =>
{
statusLabel.Text = e.Value;
}));
};

page.Controls.Add(browser);

tabControl.TabPages.Add(page);

tabControl.SelectedTab = page;
}

最佳答案

您不应该使用 SingleProcess 进行生产,您实际上可以离开多进程模式 (SingleProcess=false) 但需要 disable Visual Studio Hosting Process你不会有调试问题(旋转等待光标)

关于c# - CefWebBrowser 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14393328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com