CEF 加載網頁偶爾出現白屏現象,下面是一部分代碼
namespace CefDemo.bs
{
public partial class BsCtl
{
CefBrowser bs;
Control parent;
public BsCtl(Control ctl,string url)
{
parent = ctl;
var cwi = CefWindowInfo.Create();
cwi.SetAsChild(parent.Handle, new CefRectangle(0, 0, parent.Width, parent.Height));
var bc = new BsClient();
bc.OnCreated += bc_OnCreated;
var bs = new CefBrowserSettings() { };
CefBrowserHost.CreateBrowser(cwi, bc, bs, url);
parent.SizeChanged += parent_SizeChanged;
}
void bc_OnCreated(object sender, EventArgs e)
{
bs = (CefBrowser)sender;
var handle = bs.GetHost().GetWindowHandle();
ResizeWindow(handle,parent.Width,parent.Height);
}
void parent_SizeChanged(object sender, EventArgs e)
{
if (bs != null)
{
var handle = bs.GetHost().GetWindowHandle();
ResizeWindow(handle, parent.Width, parent.Height);
}
}
private void ResizeWindow(IntPtr handle, int width, int height)
{
if (handle != IntPtr.Zero)
{
NativeMethod.SetWindowPos(handle, IntPtr.Zero,
0, 0, width, height,
0x0002 | 0x0004
);
}
}
public void LoadUrl(string url)
{
bs.GetMainFrame().LoadUrl(url);
}
}
}
uj5u.com熱心網友回復:
我也遇到相同的問題,跪求解決方法uj5u.com熱心網友回復:
我也是遇到同樣的問題,同求!!!uj5u.com熱心網友回復:
換個LIB試試,代碼包里面LIB700多M 官網上40M的LIB好用uj5u.com熱心網友回復:
static void Main()
{
try
{
//注冊Log4
log4net.Config.XmlConfigurator.Configure();
CefRuntime.Load();
var mainArgs = new CefMainArgs(new string[] { });
var exitCode = CefRuntime.ExecuteProcess(mainArgs, null);
if (exitCode != -1)
return;
var settings = new CefSettings
{
SingleProcess = false,
//MultiThreadedMessageLoop = true,
MultiThreadedMessageLoop = false,
LogSeverity = CefLogSeverity.Disable,
Locale = "zh-CN",
LogFile = "CefGlue.log",
};
CefRuntime.Initialize(mainArgs, settings, null);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (!settings.MultiThreadedMessageLoop)
{
Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
}
Application.Run(new FrmLogin());
CefRuntime.Shutdown();
}
catch (Exception ex)
{
LogHelper.error("Main", "Main", ex.Message);
}
}
后面把 MultiThreadedMessageLoop = false,改成這樣,白屏就少了 ,但還是有幾率會變白屏。至少可以用了
uj5u.com熱心網友回復:
我也遇到了相同的問題,我下載了最新版的cef3-76就沒有這個問題了。轉載請註明出處,本文鏈接:https://www.uj5u.com/net/106081.html
標籤:C#
上一篇:如何模擬人工操作實作流量充值?
下一篇:wpf 帶箭頭圓弧控制元件開發
