Runar Ovesen Hjerpbakk

Science-based software development

WinForms

Windows Forms + CefSharp = grey content?

I've lately been evaluating CefSharp to use as an embedded browser in an old Windows Forms project.

The examples are great and the packages from nuget are easy to use, but I ran into an annoying issue. The content of the loaded page was sometimes grey. Nothing but grey. However, when I resized the embedded browser window, the page appeared. Just as it should. What is going on here?

The browser-control was added to the Form in a normal fashion:

...
browser.Dock = DockStyle.Fill;
...
Controls.Add(browser);

The appearance of the page content after resize was a clue. Perhaps the content was loaded correctly, but the control was too small to show it? Curious that DockStyle.Fill didn't do the trick as it usually does, but worth a try:

...
browser.Dock = DockStyle.Fill;
browser.Size = Size;
...
Controls.Add(browser);

Now the browser always has the correct size and all is well, or rather, as well as can be while working with Windows Forms...

Read More