1

Whenever I use initialize component I lose my data such as the selected index on my combo box. I tried declaring the browser in the form load and then just using the load url function under a button but that did not work. Here is the code:

int tracker;
    string LocationTracker;
    tracker = (cbEventsList.SelectedIndex);


    lblLocation.Text = cData[tracker];
    LocationTracker = cData[tracker];


    //In this button the program takes the information previosuly entered into the Enter Event Tab and loads it on the lab
    //InitializeComponent();
    // BrowserView browserView = new WinFormsBrowserView();

    // Controls.Add((Control)browserView);
    browserView.Browser.LoadURL("https://www.google.com/maps/place/" + cData[tracker]);


}

private void btnLoadNew_Click(object sender, EventArgs e)
{
    InitializeComponent();
    BrowserView browserView = new WinFormsBrowserView();

    Controls.Add((Control)browserView);
    browserView.Browser.LoadURL("https://www.google.com/maps/place/");

}

private void MapView_Load(object sender, EventArgs e)
{
    //   btnLoadNew.Visible = false;
    InitializeComponent();
    BrowserView browserView = new WinFormsBrowserView();

    Controls.Add((Control)browserView);
    browserView.Browser.LoadURL("https://www.google.com/maps/place/");
}
Right leg
  • 16,080
  • 7
  • 48
  • 81

1 Answers1

0

You can initialize BrowserView in the Form constructor, then store it as a private field and use this field to load other URLs when necessary:

using DotNetBrowser;
using DotNetBrowser.WinForms;
using System;
using System.Windows.Forms;

namespace WinFormsSampleCS
{
    public partial class Form1 : Form
    {
        private BrowserView browserView;

        public Form1()
        {
            InitializeComponent();
            browserView = new WinFormsBrowserView();
            Controls.Add((Control)browserView);

            //Load initial URL here, if necessary 
            browserView.Browser.LoadURL("https://www.google.com/maps/place/");
        }

        private void btnLoadNew_Click(object sender, EventArgs e)
        {
            //load another URL on button click
            browserView.Browser.LoadURL("https://www.google.com/maps/place/");
        }
    }
}

As you can see, it is not necessary at all to call InitializeComponent() several times.

Anna Dolbina
  • 1
  • 1
  • 8
  • 9