Created
October 13, 2014 07:22
-
-
Save jankurianski/6e3c6ddda54bbf6eba54 to your computer and use it in GitHub Desktop.
Avoid locking in premature size in CEF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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