Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Print page sizes and guidelines (Read 3142 times)
Nic
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 7
Joined: Feb 18th, 2015
Print page sizes and guidelines
Feb 18th, 2015 at 1:18am
Print Post  
How might I go about changing things to allow for:

  • Being able to select paper sizes other than letter
  • Being able to display a guideline to the user so they know if their chart is going to be cut off by printing
  • Have diagram bounds only match whole pages.


I noticed one of the demo/example programs in the past seemed to have the ability to do something like this, at least the second one, as it had a single page display style similar to MS Word.

(Okay actually I went and found the demo and it wasn't actually using a "page" just a large un-interactable shape node that sat underneath everything else. And while this sounded like a great hacked together solution it doesn't allow the use to see the grid at all.)

My current solution for showing guidelines was to use a transparent background image that had a single pixel thick line around the edges that was the same size as a sheet of paper's print area. The problem here is I then can't have any other paper sizes other than letter nor can I represent landscape prints, unless I make a background image to suit every combination and then make the bounds of the diagrams suit these dimensions.

Thanks in advance.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Print page sizes and guidelines
Reply #1 - Feb 18th, 2015 at 9:15am
Print Post  
You can use the standard PageSetupDialog to let users select paper size, and draw guidelines from DrawBackground or DrawForeground event:

Code
Select All
PageSettings pageSettings = new PageSettings();

void OnDrawForeground(object sender, DiagramEventArgs e)
{
	var pageBounds = pageSettings.Bounds;
	var margins = pageSettings.Margins;
	var pageSize = new RectangleF(0, 0,
		pageBounds.Width - margins.Left - margins.Right,
		pageBounds.Height - margins.Top - margins.Bottom);

	// convert from hundredths of an inch
	var unit = new MeasureUnit("", 100);
	pageSize = unit.Convert(
		pageSize, diagram.MeasureUnit, diagramView);

	using (var pen = new System.Drawing.Pen(
		Color.Gray, 0) { DashStyle = DashStyle.Dash })
	{
		var r = diagram.Bounds;
		for (float x = r.Left; x < r.Right; x += pageSize.Width)
			e.Graphics.DrawLine(pen, x, r.Top, x, r.Bottom);
		for (float y = r.Top; y < r.Bottom; y += pageSize.Height)
			e.Graphics.DrawLine(pen, r.Left, y, r.Right, y);
	}
}

void OnFilePageSetup(object sender, EventArgs e)
{
	var dlg = new PageSetupDialog();
	dlg.PageSettings = pageSettings;
	if (dlg.ShowDialog() == DialogResult.OK)
		diagramView.Invalidate();
}

void OnFilePrint(object sender, EventArgs e)
{
	// don't draw guidelines while printing
	diagram.DrawForeground -= OnDrawForeground;

	var doc = new PrintDocument();
	doc.DefaultPageSettings = pageSettings;
	diagramView.PrintOptions.Margins = pageSettings.Margins;
	diagramView.Print(doc);

	diagram.DrawForeground += OnDrawForeground;
}

void OnFilePreview(object sender, EventArgs e)
{
	// don't draw guidelines while printing
	diagram.DrawForeground -= OnDrawForeground;

	var doc = new PrintDocument();
	doc.DefaultPageSettings = pageSettings;
	diagramView.PrintOptions.Margins = pageSettings.Margins;
	diagramView.PrintPreview(doc);

	diagram.DrawForeground += OnDrawForeground;
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Nic
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 7
Joined: Feb 18th, 2015
Re: Print page sizes and guidelines
Reply #2 - Feb 20th, 2015 at 7:18pm
Print Post  
Thanks!

That looks like exactly what I was looking for!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint