Daniel Flannery
Daniel Flannery

Reputation: 1178

Order of form_load method execution

I am creating a winforms application which uses Gmaps.net. I am unable to alter the order in which on Load methods are being called. For some reason the map_load is being called before the man_Load. Is there any way to change the order of this ?

If I can provide any more information to help just ask. Thanks! Dan.

public partial class main : Form
{
    public main()
    {
        InitializeComponent();
    }

    private void main_Load(object sender, EventArgs e)
    {
        MessageBox.Show("main_load");
    }

    private void map_Load(object sender, EventArgs e)
    {
        MessageBox.Show("map_load");
    }
}

Upvotes: 1

Views: 152

Answers (1)

Daniel Peñalba
Daniel Peñalba

Reputation: 31847

It seems that you used the WinForms designer to create the map. The code behind is in the InitializeComponent() method and seems that the map is being loaded before the MainForm is loaded.

My recommendation is to create the map, once the MainForm has been loaded:

public partial class main : Form
{
    public main()
    {
        InitializeComponent();
    }

    private void main_Load(object sender, EventArgs e)
    {
        Control map = CreateMap();
        map.Docking = DockStyle.Fill;
        this.Controls.Add(map);
    }

    private Control CreateMap()
    {
       // Create a new GMaps.NET object, intialize it and return
    }
}

Hope it helps.

Upvotes: 3

Related Questions