cefsharp / CefSharp

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework
http://cefsharp.github.io/
Other
9.82k stars 2.92k forks source link

WinForms - Incorrectly positioned inside Form with FormStartPosition set to CenterParent #3625

Closed ohlookitsben closed 2 years ago

ohlookitsben commented 3 years ago
amaitland commented 3 years ago

Thanks for the detailed bug report 👍

If you add a border around the ChromiumWebBrowser instance does it fill the entire Form when the control renders incorrectly? If yes then it's probably a timing issue when the internal CefBrowser has it's width/height set.

ohlookitsben commented 3 years ago

Apologies for the delay in response. I haven't easily been able to capture an image of the control with a border around it - the incidence of this failure on my test application has really dropped off lately and I'm not sure why. I've captured a video of the failure in our actual application that might answer some questions around how the control is being laid out.

A few observations

https://www.youtube.com/watch?v=z3K91syDl5U

amaitland commented 3 years ago

I've captured a video of the failure in our actual application that might answer some questions around how the control is being laid out.

If you can reliably reproduce the problem in your application then you can do some debugging. CefSharp is built with GitLink, there are instructions on the GitLink site about how to enable within Visual Studio. You can step into ChromiumWebBrowser and add some breakpoints to the following:

The video doesn't really tell me anything meaningful.

amaitland commented 3 years ago

I just ran your example three times (total of 150 browsers created) and I've yet to see the problem reproduce.

Does the problem reproduce on multiple machines with different hardware/software configurations or is it limited to a single hardware/software config?

ohlookitsben commented 3 years ago

The problem is reproducible on a few different machine configurations. We've had 2 or 3 clients report this issue that would be using different machines to us. The machines we're using for development also display these issues. The models we know of that can reproduce this are Dell Precision 5530, Dell Precision M4800, Panasonic Toughbook FZ-G1, Dell Precision 7530. The issue has been long-standing for us, and we have records of it back to CEF 65.0, so I don't think this is likely to be a recently introduced thing.

amaitland commented 3 years ago

If you can reproduce the problem on a machine with visual studio installed you should fairly easily be able to debug this. If the ChromiumWebBrowser instance fills the space correctly then it's likely something related to the internal ResizeBrowser calls.

ohlookitsben commented 3 years ago

Still in the process of digging into this:

juanbucz commented 2 years ago

Has there been any resolution on this issue?

I'm seeing the behaviour consistently here.

I create a simple Form with a panel. I add the Cef control to the panel. The contents are misaligned and offset (down and to the right). I've tried several small sample apps I found on the web. I've tried previously releases of the Cef library. I see the same results every time.

I've attached a zip of my project here.

Can anyone shine any light on this? Until I can get this resolved the control will be unusable for us.

Thanks CefTest.zip

juanbucz commented 2 years ago

After much googling, I found a solution that worked for me. The issue appears to be DPI related.

I added this to my winforms App.config file:

  <System.Windows.Forms.ApplicationConfigurationSection>
    <add key="DpiAware" value="true"/>
    <add key="DpiAwareness" value="PerMonitorV2"/>
  </System.Windows.Forms.ApplicationConfigurationSection>

I also set my .Net Framework version to be 4.7.2 (anything prior to that causes the same issue).

With the combination of these changes, the Cef browser control aligns correctly in it's parent container.

Hope this helps someone else.

amaitland commented 2 years ago

The issue appears to be DPI related.

See https://github.com/cefsharp/CefSharp/wiki/General-Usage#high-dpi-displayssupport for information regarding DPI.

This particular issue isn't related to DPI.

amaitland commented 2 years ago

I'm going to close this issue for now as I've not seen any further reports and I've never been able to reproduce the issue myself so this isn't something I can debug.

Based on the described behaviour it's entirely possible it's a problem deep within Chromium that only reproduces with a set GPU.