Print Layout Dialog

Feb 24, 2012 at 6:29 PM
Edited Feb 24, 2012 at 6:30 PM

Hi all, how can I relate the map contents of my main window with the layout form dialog? I want to show the contents of map into the layout page setup. From a custom  button I have made I call it with

_layout = new LayoutForm {MapControl = map1};

 

and then

 

_layout.ShowDialog(this);



but with no results. Any Ideas of how to achieve it? Thanks in Advance
Mar 14, 2012 at 12:50 AM

As I have found no solution to my problem, I want to ask again differently. I have  form which contains a map. This is map1. I want to print this map by calling

            DotSpatial.Controls.LayoutForm frm = new DotSpatial.Controls.LayoutForm();
            frm.MapControl = map1;
            frm.Show();

from a button that I have placed on my form. When I do so, I only see a blank page on layout form. What am I doing wrong?

This is the same code from tutorial 4.

Developer
Mar 14, 2012 at 8:37 PM

On the Layout form there is a toolbar with icons representing legend, compass rose, scalebar, map etc. You need to use these buttons to include the components you want on your printout.

Perhaps there would be a way to programmatically include these items as well.

Mar 20, 2012 at 1:57 PM

Thank you mudnug for your reply and sorry for my delay. The issue here is that the layout control must be on a seperate form. If I place it on the form which contains the map, everything works fine. But if -lets say- map control is placed on form1 and the layoutcontrol is placed on form2 how can i set the map control to map of form1? On the properties pane it says none (on the map control dropdown list) and programmatically does not work, at least with the way I wrote above.

Developer
Mar 20, 2012 at 5:24 PM

There are several ways of doing that with varying degrees of maintainability. This question is not specific to DotSpatial, however.

Check the top two answers on this page for two opinions: http://stackoverflow.com/questions/8566/best-way-to-access-a-control-on-another-form-in-winforms

Another option is to set the Modifier property of the map control to public. You will need a reference to form1 that you can access from form2.

A more involved, but perhaps a better solution would involve using our extension framework and dependency injection to get the reference to the map. If form2 is in an extension it can get the reference by using App.Map.

Mar 20, 2012 at 8:20 PM

Thank you so much!! I will have a look at it

Developer
Mar 21, 2012 at 3:02 AM

Does the print layout draw correctly for you guys?  Only a portion of the map draws for me.  Legends and Text draw as expected.  The problem also shows up if you select the map and execute the Select/Convert to bitmap menu option. 

Developer
Mar 21, 2012 at 5:51 PM

Try using the pan map tool on the toolbar in the Print Layout dialog. Does this help?

Mar 22, 2012 at 11:25 PM

No it does not. I am confused. Apart from this is there a way to get the file name of the file I open on the map through the add data button (green cross) of the spatial toolstrip bar? Something like getfilename method? I 've read something about Ifeaturelayer.text but all I get is legend1. I want the name of the file I open, like it is shown on the legend.

Developer
Mar 23, 2012 at 5:34 PM

Try layer.LegendText.

As far as the Print Layout dialog is concerned, I've noticed that Polygon shapefiles do not appear correctly when printing.

Mar 23, 2012 at 7:54 PM

I have managed to create a print layout dialog with a print layout control from visual studio's toolbox. Now all I want is to get the file name of the file I add on the map and print it on the page. You mean map1.layer.LegentText();

Developer
Mar 23, 2012 at 9:07 PM

So, extending your sample ... you can get the name of the layer, but I don't know how to add a text tag to the LayerDialog programatically. 

DotSpatial.Controls.LayoutForm frm = new DotSpatial.Controls.LayoutForm();
string name = map1.Layers[0].LegendText;
            frm.MapControl = map1;
            frm.Show();
Mar 24, 2012 at 2:02 PM
string name = map1.Layers[0].LegendText; 

Thank you, Thank you, Thank you!!! That was the missing part!!! I Create a rectangle and then a font and put them all together.

  Rectangle rectangle = new Rectangle(10, 10, map.Width, map.Height);
    Font f = new Font("Arial", 12, FontStyle.Bold, GraphicsUnit.Point);

StringFormat stringFormat = new StringFormat();

 
e.Graphics.DrawString(name, f, Brushes.Red, rectangle, stringFormat);
    e.Graphics.DrawRectangle(Pens.Black, rectangle);
Apr 21, 2012 at 5:46 AM
Edited Apr 21, 2012 at 5:47 AM

How can I programmatically insert map to print layout form instead of using ribbon tools in print layout form?

Feb 24, 2014 at 11:02 AM
nikchan wrote:
I have managed to create a print layout dialog with a print layout control from visual studio's toolbox. Now all I want is to get the file name of the file I add on the map and print it on the page. You mean map1.layer.LegentText();
Hello nikchan,
i have a similar Problem: I'm trying to create a report as text based on the attributes of some layers and a selection the user makes. And it would be nice if I could use the layout Dialog to combine the map and the text programmatically.

So can you give me a hint how created the print layout control from visual studio's toolbox and inserted the map?

Thanks in advance,

Claudia