-5

This is my current code: https://hastebin.com/ifejusezat.cs

This is a screenshot of what I see: https://gyazo.com/2ee9b1210649ca8ec61e3fa7e645a286

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        BrowserView browserView = new WinFormsBrowserView();
        Controls.Add((Control)browserView);
        browserView.Browser.LoadURL("http://www.google.com");
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        BrowserView browserView = new WinFormsBrowserView(BrowserFactory.Create());
        Control browserWindow = (Control)browserView;
        browserWindow.Dock = DockStyle.Fill;
        Controls.Add(browserWindow);
    }
}
The Muffin Man
  • 19,585
  • 30
  • 119
  • 191
RedBox
  • 1
  • 2
  • 1
    Do you know about size property of Control? You need to learn about it and use it to solve your issue. – Chetan Dec 09 '18 at 05:37
  • @ChetanRanpariya RedBox is a new contributor to this site. Let's not use that as an opportunity to act like a high school bully. Furthermore, they are using the `dock fill` property and at first glance I would think that should maximize the control. – The Muffin Man Dec 09 '18 at 05:40
  • I am not sure which part of my comment was bullying. Giving directions around finding solution is not bullying. – Chetan Dec 09 '18 at 05:47
  • @RedBox Try doing following. Remove all code from `Form1()` and `Form_Load`. Open the form in design mode, add the WebBrowserView control to the form and set it's properties such as "Size" etc from the Properties Window. – Chetan Dec 09 '18 at 11:32

2 Answers2

0

Updated answer: This is my complete Form1.cs (taken directly from the teamdev website), and it works (see image) without needing to resize.

using DotNetBrowser;
using DotNetBrowser.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinFormsSampleCSLightweight
{
    public partial class Form1 : Form
    {

        private readonly BrowserView browserView;

        public Form1()
        {
            InitializeComponent();

            browserView = new WinFormsBrowserView(BrowserFactory.Create(BrowserType.LIGHTWEIGHT));
            Controls.Add((Control)browserView);
            browserView.Browser.LoadURL("http://www.google.com");
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (browserView != null)
            {
                browserView.Dispose();
                browserView.Browser.Dispose();
            }
        }
    }
}

enter image description here


Original answer: You can try the UpdateSize method on your browser view.

browserView.UpdateSize(someWidth, someHeight);

Or you can try to size the document that is viewed.

public void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    //For the case when the control's Dock property is DockStyle.Fill
    this.Width = WebBrowser.Document.Body.ScrollRectangle.Width + 40; //40 is for border
    this.Height = WebBrowser.Document.Body.ScrollRectangle.Height + 40; //40 is for border
    //For the case when the control is not docked
    WebBrowser.Size = WebBrowser.Document.Body.ScrollRectangle.Size;
}
clairestreb
  • 1,243
  • 12
  • 24
  • This didn't work, I have tried this before and tried it again. – RedBox Dec 09 '18 at 06:08
  • Another error. Here is my error: `Form1' does not contain a definition for 'Form1_Load' and no extension method 'Form1_Load' accepting a first argument of type 'Form1' could be found (are you missing a using directive or an assembly reference?)` I am more of a beginner at C# and I have never had this error before. – RedBox Dec 09 '18 at 18:11
  • @Redbox You can download the sample solution from the teamdev URL I provided in my answer, and use that as a starting point. Or, you can see stackoverflow answer for the answer to your new error: https://stackoverflow.com/questions/14172404/johny-form1-does-not-contain-a-definition-for-form1-load. I recommend you accept this answer as your solution then post new questions for new problems, but first look to see if your problem has already been asked before. – clairestreb Dec 09 '18 at 18:54
  • Just fixed the error for that part, now i'm having the same problem (just the tiny window is a bit bigger now). EDIT: Samples aren't working. – RedBox Dec 09 '18 at 21:03
0

If your are using DotNetBrowser 1.9 use the control properties to set Dock to DockFill

Control browserControl = (Control)browserView;
browserControl.Dock = DockStyle.Fill;
Controls.Add(browserControl);
M. Serseg
  • 103
  • 1
  • 1
  • 4