Partager via


Creating the most basic Windows Form

Note:  this entry references code for an older version of VE3D.  The newest code samples are here

The samples that can be downloaded below demonstrate creating a basic Windows Application with a VE3D control on it (SimpleForm), however, I wanted to go over the most basic steps.  The sample does not use the Toolbox, but I will.

Step 1: Make sure the VE3D control is installed by visiting https://maps.live.com and switching to 3D. 

Step 2: Select Tools->Choose Toolbox Items... 

Step 3: Make sure GlobeControl is checked in .NET Framework Components tab.  The version should be 2.0.711.13001.  GlobeControl should now show up in your Toolbox under the General section with a gear icon next to it.

Choose Toobox Items dialog

Step 4: Create a new C# Windows Application in Visual Studio 2005.

Step 5: Select GlobeControl from your Toolbox and drop it onto your form.  It should show up with just a big, grey dot in the middle and "GlobeControl" written across it.  This is just the designer view.  If you run the application at this point, you'll see the globe in 3D, but only with the outer most model and if you zoom in you'll just get fuzzy green.  The reason is that we haven't set up any data sources yet, so...

Step 6: Make sure your form is selected (not the GlobeControl) and add a Load event (select the lightening bolt for events in the Properties pane, find Load and double click on it).  Make sure it looks like this:

private

void Form1_Load(object sender, EventArgs e)
{
    this.globeControl1.Host.DataSources.Add(new DataSourceLayerData("Elevation", "Elevation", @"https://maps.live.com//Manifests/HD.xml", DataSourceUsage.ElevationMap));
    this.globeControl1.Host.DataSources.Add(new DataSourceLayerData("Texture", "Texture", @"https://maps.live.com//Manifests/HT.xml", DataSourceUsage.TextureMap));
    this.globeControl1.Host.DataSources.Add(new DataSourceLayerData("Models", "Models", @"https://maps.live.com//Manifests/MO.xml", DataSourceUsage.Model));
}

Step 7: To use the DataSource classes, you'll need to right-click on your project's references and select Add Reference..., select the Browse tab and browse to "C:\Program Files\Virtual Earth 3D".  Select "Microsoft.MapPoint.Data" and "Microsoft.MapPoint.Rendering3D.Utility" and hit OK.

Step 8: Run your application and enjoy!

Definitely look at the samples for more goodness, but these are the basic steps to get started.

Comments

  • Anonymous
    April 21, 2008
    How would I force the user to download the plugin if it's not already installed? If I'm not wrong this app would crash on a machine that doesn't have the plugin installed.

  • Anonymous
    April 22, 2008
    No exception is thrown until a method using the assembly is called. In this case the Form constructor. In Program.cs before the Form is created you can manually probe for an assembly and take some action if it can't be loaded. Sample probing code: try {    System.Reflection.Assembly a = System.Reflection.Assembly.Load("Microsoft.MapPoint.Rendering3D, Version=2.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); } catch (Exception e) {    // Handle error case here. Maybe show a different form with a link to download Virtual Earth 3D. }

  • Anonymous
    December 25, 2008
    Hi there, I’m working on porting my Location Aware WPF Application to Virtual Earth 3D Managed WinForms