Skip to content

Instantly share code, notes, and snippets.

@jankurianski
Created October 13, 2014 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jankurianski/6e3c6ddda54bbf6eba54 to your computer and use it in GitHub Desktop.
Save jankurianski/6e3c6ddda54bbf6eba54 to your computer and use it in GitHub Desktop.
Avoid locking in premature size in CEF
bool setInitialSize = false;
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
if (setInitialSize && managedCefBrowserAdapter != null)
managedCefBrowserAdapter.OnSizeChanged();
}
protected override void OnVisibleChanged(EventArgs e)
{
base.OnVisibleChanged(e);
// We must wait until the control is visible before calling OnSizeChanged.
// Otherwise CEF will lock in first size we called it with until the next paint,
// and our custom form sizing may further change the size upon OnShown().
if (Visible && !setInitialSize && managedCefBrowserAdapter != null) {
MethodInvoker mi = () => {
managedCefBrowserAdapter.OnSizeChanged();
this.setInitialSize = true;
};
BeginInvoke((Delegate)mi);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment