Skip to content
This repository has been archived by the owner on Sep 3, 2019. It is now read-only.

System.NullReferenceException in MapControl at design time #277

Open
OgreTransporter opened this issue Jan 14, 2016 · 0 comments
Open

System.NullReferenceException in MapControl at design time #277

OgreTransporter opened this issue Jan 14, 2016 · 0 comments

Comments

@OgreTransporter
Copy link

I want to display an OSM map on a control, so I've downloaded OsmShap daily build. If I drag and drop a new MapControl to a WinForm, I'll get the following message:

System.NullReferenceException: Object reference not set to an instance of an object
at OsmSharp.WinForms.UI.MapControl.OnPaint(PaintEventArgs e) in D:\OsmSharp\OsmSharp.UI\OsmSharp.WinForms.UI\MapControl.cs:205
at

The error appears because there is no map at design time, so a check for a valid map is needed. I've downloaded the source and created a workaround:

        protected override void OnPaint(PaintEventArgs e)
        {
            long ticksBefore = DateTime.Now.Ticks;

            var g = e.Graphics;

            if(this.Map == null)
            {
                g.FillRectangle(Brushes.White, 0, 0, this.Width, this.Height);
                Pen wred = (Pen)Pens.Red.Clone();
                wred.Width = 3.0f;
                g.DrawRectangle(wred, 1, 1, this.Width - 3, this.Height - 3);
                g.DrawLine(wred, 1, 1, this.Width - 3, this.Height - 3);
                g.DrawLine(wred, 1, this.Height - 3, this.Width - 3, 1);
                return;
            }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant