Workaround/tempFix for WindowsMobile GMapControl

Topics: Windows Mobile
Feb 7, 2011 at 10:12 PM

I really didn't see this anywhere on the forums so I thought this might help some people who are having problems with the [Design] mode when creating their windows mobile application. What I did was create the map component outside the InitializeComponent() method like so:

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GMap.NET;
using GMap.NET.CacheProviders;
using GMap.NET.Internals;
using GMap.NET.WindowsForms;
using GMap.NET.WindowsMobile;

namespace ColmbanGpsMobile
{
    public partial class MainForm : Form
    {
        public GMapControl MainMap;

        public MainForm()
        {
            InitializeComponent();
            MainMapInitialization();
        }

        #region System
        private void MainMapInitialization()
        {
            this.MainMap = new GMapControl();

            this.tabPageMapData.Controls.Add(this.MainMap);

            this.MainMap.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.MainMap.CanDragMap = true;
            this.MainMap.Dock = System.Windows.Forms.DockStyle.Fill;
            this.MainMap.LevelsKeepInMemmory = 5;
            this.MainMap.Location = new System.Drawing.Point(0, 0);
            this.MainMap.MarkersEnabled = true;
            this.MainMap.MapType = MapType.OpenStreetMap;
            this.MainMap.MaxZoom = 15;
            this.MainMap.MinZoom = 0;
            this.MainMap.MouseWheelZoomType = GMap.NET.MouseWheelZoomType.MousePositionAndCenter;
            this.MainMap.Name = "MainMap";
            this.MainMap.PolygonsEnabled = true;
            this.MainMap.RetryLoadTile = 0;
            this.MainMap.RoutesEnabled = true;
            this.MainMap.ShowTileGridLines = false;
            this.MainMap.Size = new System.Drawing.Size(240, 268);
            this.MainMap.TabIndex = 8;
            this.MainMap.Zoom = 3;
        }
        #endregion
    }
}

By doing this the [Design] mode doesn't break. I have it docked to fill a tabpage, but you can change that to fill a panel so you can move it around and resize it easier just by moving the panel around in the [Design] mode and do all the coding in the MainForm.cs like usual.

Feb 7, 2011 at 10:30 PM

thanks for sharing ;}