CefWebBrowser doesn't show up

前端 未结 4 2059
刺人心
刺人心 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 11:55

    I also had the same problem,I solved it by modify "BrowserSubprocessPath",the defualt is like this:

            //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",
            };
    

    Because I had changed the application output directory,so the "browserProcessPath" is invalid,then I modify the "browserProcessPath" to match the output directory so that the application can find it.

    But,I still can not understand the meaning and usage of "browserProcessPath "

    0 讨论(0)
  • 2021-02-03 11:56

    You never added the control to the form's controls collection, at least in the samples you showed.

    0 讨论(0)
  • 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;
        }
    
    0 讨论(0)
  • 2021-02-03 12:07

    You shouldn't use SingleProcess for production, you can actually leave the multiprocess mode (SingleProcess=false) but need to disable Visual Studio Hosting Process and you wont have problem for debugging (spinning wait cursor)

    0 讨论(0)
提交回复
热议问题