Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Export Selected Map Items to an Image

The following example demonstrates how to export selected map items to an image.

To do this, handle the MapControl.ExportMapItem event and set the ExportMapItemEventArgs.Cancel property to true if the map item is not selected (the ExportMapItemEventArgs.IsSelected property is set to false). Then, call the MapControl.ExportToImage method using the map path (where the map image should be stored) and the specified image format (e.g., .png).

using System;
using System.Windows.Forms;
using System.Drawing.Imaging;
using DevExpress.XtraMap;
using System.Diagnostics;

namespace ExportSelectedItems {
    public partial class Form1 : Form {
        string mapPath = "Image.png";

        public Form1() {
            InitializeComponent();
            mapControl1.ExportMapItem += mapControl1_ExportMapItem;
        }

        private void mapControl1_ExportMapItem(object sender, ExportMapItemEventArgs e) {
            if (!e.IsSelected)
                e.Cancel = true;
        }

        private void simpleButton1_Click(object sender, EventArgs e) {
            mapControl1.ExportToImage(mapPath, ImageFormat.Png);
            Process.Start(mapPath);
        }
    }
}