C# CefWebBrowser不';我没有出现
解决方案:C# CefWebBrowser不';我没有出现,c#,winforms,webbrowser-control,chromium,chromium-embedded,C#,Winforms,Webbrowser Control,Chromium,Chromium Embedded,解决方案: 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
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;
}
此问题是由于未在Program.cs中加载CEF运行时造成的。只需将示例文件中的所有代码复制到Program.cs
然后,如果您的CefWebBrowser被卡住并且有“旋转等待鼠标光标”,则将SingleProcess设置为true
原因是,如果从已识别的辅助进程调用浏览器,整个进程将被阻止,直到进程结束
问题:
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;
}
有没有人有在WinForm中使用CEF(Chromium Embedded Framework)的经验
这个部件折磨了我一整天。我不能让它工作。
它只是没有出现
所以我的问题是:如何在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();
}
}
更新:
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;
}
我正在尝试使用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;
}
您从未将控件添加到表单的控件集合中,至少在您显示的示例中是这样。我在启动浏览器时也遇到了问题。我可以加载所有CEF DLL,但浏览器不会显示!我得到的只是在控件上方悬停时旋转的等待鼠标光标 不幸的是,我还没有找到问题的根源,但由于示例项目CefGlue.Client有效,我只是将其复制到我的解决方案中 另外,我看不出您是如何初始化CEF运行时的。看看CefGlue.Client中的Program.cs是如何完成的,但基本上是这样的:
[STAThread]
private static int Main(string[] args)
{
try
{
CefRuntime.Load();
}
catch (DllNotFoundException ex)
{
MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return 1;
}
catch (CefRuntimeException ex)
{
MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return 2;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return 3;
}
var mainArgs = new CefMainArgs(args);
var app = new DemoApp();
var exitCode = CefRuntime.ExecuteProcess(mainArgs, app);
if (exitCode != -1)
return exitCode;
var settings = new CefSettings
{
// BrowserSubprocessPath = @"D:\fddima\Projects\Xilium\Xilium.CefGlue\CefGlue.Demo\bin\Release\Xilium.CefGlue.Demo.exe",
SingleProcess = false,
MultiThreadedMessageLoop = true,
LogSeverity = CefLogSeverity.Disable,
LogFile = "CefGlue.log",
};
CefRuntime.Initialize(mainArgs, settings, app);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (!settings.MultiThreadedMessageLoop)
{
Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
}
Application.Run(new MainForm());
CefRuntime.Shutdown();
return 0;
}
您不应该在生产中使用
SingleProcess
,您实际上可以离开多进程模式(SingleProcess=false
),但需要这样做,并且您不会有调试问题(旋转等待光标)我也有同样的问题,我通过修改“BrowserSubprocessPath”解决了它,情况如下:
//var browserProcessPath = CombinePaths(localFolder, "..", "..", "..",
// "CefGlue.Demo.WinForms", "bin", "Release", "Xilium.CefGlue.Demo.WinForms.exe");
var browserProcessPath = CombinePaths(localFolder, "Xilium.CefGlue.Demo.WinForms.exe");
var settings = new CefSettings
{
BrowserSubprocessPath = browserProcessPath,
SingleProcess = false,
MultiThreadedMessageLoop = true,
LogSeverity = CefLogSeverity.Disable,
LogFile = "CefGlue.log",
};
因为我更改了应用程序输出目录,所以“browserProcessPath”无效,所以我修改了“browserProcessPath”以匹配输出目录,以便应用程序可以找到它
但是,我仍然无法理解“browserProcessPath”的含义和用法。?7小时后没有回复?……请有人帮忙……ayaya~~没有人没有人la~~~我确实将CefBrowser添加到tabPage组件中,然后将其添加到tabControl中,tabControl已添加到WinForm的控件集合中。看到我的最新代码嗨圣代,非常感谢!我已经解决了这个问题。是,这是由于未在Program.cs中加载CEF运行时造成的。我也解决了你的问题,那就是“旋转等待鼠标光标”。这是因为SingleProcess被设置为false,因此如果从已识别的辅助进程调用浏览器,它将阻止整个进程,直到退出为止。因此,请在我的帖子中查看解决方案。但出于礼貌,我会把你的帖子标记为答案,因为你是唯一提供相关解决方案的人^^^干杯谢谢你,弗兰瓦!我会试试你的解决办法。RegardS关于在你的应用中初始化CEF的详细信息,你可以在这里找到:尽管在Mac throuh Xilium.CefGlue上,它目前只是运行模式(SingleProcess=true),只是注意到存在平台差异。