Beispiel #1
0
        private void btnToBitmap_Click(object sender, RoutedEventArgs e)
        {
            PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];
            PagePrinterLayer          pagePrinterLayer          = printerInteractiveOverlay.PrinterLayers["PageLayer"] as PagePrinterLayer;

            // Create a bitmap that is the size of the pages bounding box.  The page by default is in points unit
            // system which is very similar to pixels so that ampping is nice.
            GeoImage bitmap = null;

            try
            {
                bitmap = new GeoImage((int)pagePrinterLayer.GetBoundingBox().Width, (int)pagePrinterLayer.GetBoundingBox().Height);

                // Create a GeoCanvas and start the drawing
                GeoCanvas gdiPlusGeoCanvas = GeoCanvas.CreateDefaultGeoCanvas();
                gdiPlusGeoCanvas.BeginDrawing(bitmap, pagePrinterLayer.GetBoundingBox(), Map1.MapUnit);

                // Loop through all of the PrintingLayer in the PrinterInteractiveOverlay and print all of the
                // except for the PagePrinterLayer
                Collection <SimpleCandidate> labelsInAllLayers = new Collection <SimpleCandidate>();
                foreach (PrinterLayer printerLayer in printerInteractiveOverlay.PrinterLayers)
                {
                    printerLayer.IsDrawing = true;
                    if (!(printerLayer is PagePrinterLayer))
                    {
                        printerLayer.Draw(gdiPlusGeoCanvas, labelsInAllLayers);
                    }
                    printerLayer.IsDrawing = false;
                }

                // End the drawing
                gdiPlusGeoCanvas.EndDrawing();

                //Save the resulting bitmap to a file and open the file to show the user
                string filename = "PrintingResults.bmp";
                bitmap.Save(filename);
                Process.Start("explorer.exe", filename);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " " + ex.StackTrace, "Exception");
            }
            finally
            {
                if (bitmap != null)
                {
                    bitmap.Dispose();
                }
            }
        }
Beispiel #2
0
        private void btnToPrintPreview_Click(object sender, RoutedEventArgs e)
        {
            PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];
            PagePrinterLayer          pagePrinterLayer          = printerInteractiveOverlay.PrinterLayers["PageLayer"] as PagePrinterLayer;

            PrintDialog   printDialog   = new PrintDialog();
            PrintDocument printDocument = new PrintDocument();

            printDocument.DefaultPageSettings.Landscape = true;
            if (pagePrinterLayer.Orientation == PrinterOrientation.Portrait)
            {
                printDocument.DefaultPageSettings.Landscape = false;
            }

            printDocument.DefaultPageSettings.PaperSize = GetPrintPreviewPaperSize(pagePrinterLayer);

            PrinterGeoCanvas printerGeoCanvas = new PrinterGeoCanvas();

            printerGeoCanvas.DrawingArea = printDocument.DefaultPageSettings.Bounds;
            printerGeoCanvas.BeginDrawing(printDocument, pagePrinterLayer.GetBoundingBox(), Map1.MapUnit);

            // Loop through all of the PrintingLayer in the PrinterInteractiveOverlay and print all of the
            // except for the PagePrinterLayer
            Collection <SimpleCandidate> labelsInAllLayers = new Collection <SimpleCandidate>();

            foreach (PrinterLayer printerLayer in printerInteractiveOverlay.PrinterLayers)
            {
                printerLayer.IsDrawing = true;
                if (!(printerLayer is PagePrinterLayer))
                {
                    printerLayer.Draw(printerGeoCanvas, labelsInAllLayers);
                }
                printerLayer.IsDrawing = false;
            }

            printerGeoCanvas.Flush();

            System.Windows.Forms.PrintPreviewDialog printPreviewDialog = new System.Windows.Forms.PrintPreviewDialog();
            printPreviewDialog.Document = printDocument;
            System.Windows.Forms.DialogResult dialogResult = printPreviewDialog.ShowDialog();
        }
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)mapView.InteractiveOverlays["PrintPreviewOverlay"];
            PagePrinterLayer          pagePrinterLayer          = printerInteractiveOverlay.PrinterLayers["PageLayer"] as PagePrinterLayer;

            PrintDocument printDocument = new PrintDocument();

            printDocument.DefaultPageSettings.Landscape = true;
            if (pagePrinterLayer.Orientation == PrinterOrientation.Portrait)
            {
                printDocument.DefaultPageSettings.Landscape = false;
            }

            printDocument.DefaultPageSettings.PaperSize = new PaperSize("AnsiA", 850, 1100);

            PrinterGeoCanvas printerGeoCanvas = new PrinterGeoCanvas();

            printerGeoCanvas.DrawingArea = new Rectangle(0, 0, Convert.ToInt32(printDocument.DefaultPageSettings.PrintableArea.Width), Convert.ToInt32(printDocument.DefaultPageSettings.PrintableArea.Height));
            printerGeoCanvas.BeginDrawing(printDocument, pagePrinterLayer.GetBoundingBox(), mapView.MapUnit);

            // Loop through all of the PrintingLayer in the PrinterInteractiveOverlay and print all of the
            // except for the PagePrinterLayer
            Collection <SimpleCandidate> labelsInAllLayers = new Collection <SimpleCandidate>();

            foreach (PrinterLayer printerLayer in printerInteractiveOverlay.PrinterLayers)
            {
                printerLayer.IsDrawing = true;
                if (!(printerLayer is PagePrinterLayer))
                {
                    printerLayer.Draw(printerGeoCanvas, labelsInAllLayers);
                }
                printerLayer.IsDrawing = false;
            }

            printerGeoCanvas.EndDrawing();
        }