Applies to: Nevron Diagram for .NET (Map for .NET)
How to create a simple map in WinForm application from scratch in Visual Studio?
There is no separate VS Toolbox item for the Nevron Map, the Map is part of Nevron Diagram for .NET Enterprise edition. The following getting started guide will help you create a simple Map in Windows Forms application by using Nevron Diagram for .NET Map import functionality.
Create a new WinForm application:
- Open Microsoft Visual Studio for .NET
- Select the File - New - Project command - the new project dialog will be displayed
- Select Visual C# Projects - Windows Applications
Note: VS 2010 users must switch the target framework to ".NET Framework 4" as by default Windows Forms applications target ".NET Framework 4 Client Profile". This is required, because Nevron Diagram for WinForms uses design time support features that are not present in ".NET Framework 4 Client Profile". To do this right click on the project in Solution Explorer and select properties. On the Application tab go to "Target Framework" and select ".NET Framework 4".
- Click the OK button - the designer for Form1 should automatically appear
Insert diagram components and controls
- The Nevron .NET Vision installation must register the NDrawingDocument component and NDrawingView control in the Nevron Diagram WinForm toolbox group. In case this group is created go to step 7.
- Right click on the Toolbox background. Select the "Choose Items…" command.
- In the "Customize Toolbox Items" dialog select the ".NET Framework Components" tab.
- Click on the "Browse..." button and select the Nevron.Diagram.WinForm.dll assembly located in the Nevron .NET Vision installation directory.
- The NDrawingDocument component should appear at the end of the toolbox Windows Forms list.
- Perform the same actions once again, but this time select the Nevron.Diagram.WinForm.dll assembly. As a result the NDrawingView control should appear at the end of the toolbox Windows Forms list.
- Drag and drop the NDrawingDocument to the form - it should appear in the component tray, since it is a component.
- Drag and drop the NDrawingView to the form and resize it as you see fit (or set its Dock property to Fill).
- Set the Document property of the Drawing View to Drawing Document.
- Open the solution explorer and make sure to add references to the following Nevron assemblies: Nevron.Diagram.dll; Nevron.Diagram.WinForm.dll; Nevron.Diagram.Shapes.dll; Nevron.Diagram.Templates.dll; Nevron.System.dll; and Nevron.Presentation.dll;
- Double click on Form1 to generate the Form1_Load method.
Programmatically create the map
In the Form1_Load method copy and paste the following code:
[C#]
using
System;
using
System.Drawing;
using
System.IO;
using
System.Windows.Forms;
using
Nevron.Diagram;
using
Nevron.Diagram.Maps;
using
Nevron.GraphicsCore;
...
private
void
Form1_Load(
object
sender, EventArgs e)
{
view.ViewLayout = ViewLayout.Fit;
document.Style.FillStyle =
new
NColorFillStyle(Color.FromArgb(204, 255, 204));
document.Style.StrokeStyle =
new
NStrokeStyle(
new
NLength(0.75f, NGraphicsUnit.Point), Color.FromArgb(119, 119, 119));
document.RoutingManager.Enabled =
false
;
document.BridgeManager.Enabled =
false
;
document.Bounds =
new
NRectangleF(0, 0, 500, 500);
document.BackgroundStyle.FillStyle =
new
NColorFillStyle(Color.White);
// Create the map
NEsriMap m_Map =
new
NEsriMap();
// create the COUNTRIES shape file
NEsriShapefile countries = m_Map.Add(SHAPEFILE_NAME);
countries.NameColumn =
"COUNTRY"
;
countries.TextColumn =
"COUNTRY"
;
m_Map.Read();
m_Map.Import(document, document.Bounds);
// make the Map layer the active layer so that the user can select the map shapes
string
layerName = Path.GetFileNameWithoutExtension(SHAPEFILE_NAME);
NLayer mapLayer = (NLayer)document.Layers.GetChildByName(layerName);
document.ActiveLayerUniqueId = mapLayer.UniqueId;
// size to visible shapes
document.SizeToContent(document.AutoBoundsMinSize, document.AutoBoundsPadding);
}
// select the map shape file
private
const
string
SHAPEFILE_NAME = @
"C:\Maps\southamerica_adm0.shp"
;
[VB.NET]
Imports
System
Imports
System.Drawing
Imports
System.IO
Imports
System.Windows.Forms
Imports
Nevron.Diagram
Imports
Nevron.Diagram.Maps
Imports
Nevron.GraphicsCore
...
Private
Sub
Form1_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
view.ViewLayout = ViewLayout.Fit
document.Style.FillStyle =
New
NColorFillStyle(Color.FromArgb(204, 255, 204))
document.Style.StrokeStyle =
New
NStrokeStyle(
New
NLength(0.75F, NGraphicsUnit.Point), Color.FromArgb(119, 119, 119))
document.RoutingManager.Enabled =
False
document.BridgeManager.Enabled =
False
document.Bounds =
New
NRectangleF(0, 0, 500, 500)
document.BackgroundStyle.FillStyle =
New
NColorFillStyle(Color.White)
' Create the map
Dim
m_Map
As
New
NEsriMap()
' create the COUNTRIES shape file
Dim
countries
As
NEsriShapefile = m_Map.Add(SHAPEFILE_NAME)
countries.NameColumn =
"COUNTRY"
countries.TextColumn =
"COUNTRY"
m_Map.Read()
m_Map.Import(document, document.Bounds)
' make the Map layer the active layer so that the user can select the map shapes
Dim
layerName
As
String
= Path.GetFileNameWithoutExtension(SHAPEFILE_NAME)
Dim
mapLayer
As
NLayer =
DirectCast
(document.Layers.GetChildByName(layerName), NLayer)
document.ActiveLayerUniqueId = mapLayer.UniqueId
' size to visible shapes
document.SizeToContent(document.AutoBoundsMinSize, document.AutoBoundsPadding)
End
Sub
' select the map shape file
Private
Const
SHAPEFILE_NAME
As
String
=
"C:\Maps\southamerica_adm0.shp"
Article ID: 154, Created On: 12/2/2010, Modified: 1/11/2011