CefWebBrowser doesn't show up

前端 未结 4 2131
刺人心
刺人心 2021-02-03 11:22

Solution:

This issue is caused by not loading the CefRuntime in the Program.cs. Simply copying all code in the sample file to your Program.cs.

A

4条回答
  •  名媛妹妹
    2021-02-03 12:01

    I too had problems launching the browser. I could load all the CEF DLL's, but the browser wouldn't show up! All I got was the spinning wait mouse cursor when hovering above the control.

    Unfortunately I haven't found the root of the problem, but since the sample project CefGlue.Client works, I simply copied it to my solution instead.

    Also, I don't see how you are initializing the CEF runtime. Have a look in Program.cs in CefGlue.Client how it's done, but it's basically this:

        [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;
        }
    

提交回复
热议问题