windowsforms-16501-controls-and-libraries-map-control-examples-general-how-to-format-coordinates-displayed-in-the-navigation-panel.md
This example demonstrates how to change the text of map point coordinates displayed in the navigation panel using latitude and longitude format patterns.
To do this, specify a string that will represent the pattern displayed within a coordinate label in the map navigation panel using NavigationPanelOptions.XCoordinatePattern and NavigationPanelOptions.YCoordinatePattern properties.
In this example, you can format the values of map point coordinates using a predefined list of patterns from the combo box. In the combo box, you can also specify a custom pattern using standard specifiers together with placeholders. For example: “{CP}{D}°{M}’{S:2}’’ “, where CP – is a cardinal point; D – is a degree; M - is a minute; S – is a second. Note that the precision specifier (“2”) indicates the desired number of decimal places.
using DevExpress.XtraEditors;
using System;
using System.Windows.Forms;
namespace MapCoordinatePatterns {
public partial class Form1 : Form {
string[] patterns = new string[] {
"{D:1}°{CP}",
"{CP}{D:6}°",
"{D}°{M:2}\'{CP}",
"{CP}{D}°{M:2}\'",
"{D}°{M}\'{S:4}\'\'{CP}",
"{CP}{D}°{M}\'{S:4}\'\'",
"Coordinates: {D}°{M}\'{S:2}\'\'{CP}"
};
public Form1() {
InitializeComponent();
PopulateComboBox(cbXCoordinatePattern);
PopulateComboBox(cbYCoordinatePattern);
}
private void PopulateComboBox(ComboBoxEdit comboBox) {
comboBox.Properties.Items.AddRange(patterns);
comboBox.EditValue = comboBox.Properties.Items[0];
}
private void OnXCoordinatePatternSelectedIndexChanged(object sender, EventArgs e) {
map.NavigationPanelOptions.XCoordinatePattern = cbXCoordinatePattern.EditValue as String;
}
private void OnYCoordinatePatternSelectedIndexChanged(object sender, EventArgs e) {
map.NavigationPanelOptions.YCoordinatePattern = cbYCoordinatePattern.EditValue as String;
}
}
}
Imports DevExpress.XtraEditors
Imports System
Imports System.Windows.Forms
Namespace MapCoordinatePatterns
Partial Public Class Form1
Inherits Form
Private patterns() As String = { "{D:1}°{CP}", "{CP}{D:6}°", "{D}°{M:2}'{CP}", "{CP}{D}°{M:2}'", "{D}°{M}'{S:4}''{CP}", "{CP}{D}°{M}'{S:4}''", "Coordinates: {D}°{M}'{S:2}''{CP}" }
Public Sub New()
InitializeComponent()
PopulateComboBox(cbXCoordinatePattern)
PopulateComboBox(cbYCoordinatePattern)
End Sub
Private Sub PopulateComboBox(ByVal comboBox As ComboBoxEdit)
comboBox.Properties.Items.AddRange(patterns)
comboBox.EditValue = comboBox.Properties.Items(0)
End Sub
Private Sub OnXCoordinatePatternSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cbXCoordinatePattern.SelectedIndexChanged
map.NavigationPanelOptions.XCoordinatePattern = TryCast(cbXCoordinatePattern.EditValue, String)
End Sub
Private Sub OnYCoordinatePatternSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cbYCoordinatePattern.SelectedIndexChanged
map.NavigationPanelOptions.YCoordinatePattern = TryCast(cbYCoordinatePattern.EditValue, String)
End Sub
End Class
End Namespace