0

In Windows Forms, using VB.net (VS 2017 and/or VS 2019), I programmatically create a Webbrowser control in a form to show the contents of a pdf file - it works, but one thing is strange: the pdf appears in the upper-left-hand corner of the Webbrowser, using half the height and half the width of the control (it shows up with scrollbars, so it's still readable).

The rest of the webbrowser control is there, just blank - no reason the pdf should be in just a quarter of the window. If I open the same pdf in any of a number of browsers it appears normally, that is full sized.

The fact that it's using exactly half of the height and half of the width seems to be a clue, but I can see no property or setting that would affect this. Does anyone have any ideas?

  • Could not reproduce the problem using a very simple code like `this.Controls.Add(new WebBrowser() { Dock = DockStyle.Fill, Url = new Uri(@"http://www.africau.edu/images/default/sample.pdf") });` – Reza Aghaei Jan 16 '21 at 22:32
  • I appreciate the effort. I too use DockStyle.fill, otherwise do no explicit resizing - my first thought was maybe some initial size persisted, but I don't change anything. Is there any way to determine the version of the control? Maybe your test and mine are based on different Webbrowser controls, though that makes little sense to me. – Bryan A. Bentz Jan 16 '21 at 23:05
  • 1
    The control uses the default IE version installed on Windows (in compatibility mode). My environment: .NET 4.8, Windows 10, Default IE version, DPI settings 100%. – Reza Aghaei Jan 16 '21 at 23:10
  • I did create a clean, new project, one form, one webbrowser control, two buttons (one to navigate to an HTML file, one to a PDF). I see the same odd behavior. I'd post the simple project, not sure how to do that here. – Bryan A. Bentz Jan 17 '21 at 09:42
  • You might be able to play with the `style` tags to fit it properly, like this example: https://stackoverflow.com/a/65690842/553663 Also related: https://social.msdn.microsoft.com/Forums/vstudio/en-US/cc7ba572-2b6e-40f3-862d-c9eab2d0574e/open-pdf-in-what-percentage-zoom?forum=csharpgeneral – J. Scott Elblein Jan 20 '21 at 13:17

0 Answers0