Profile Picture

NPrinterManager - PrintOnSinglePage

Posted By Mohamed Koker 11 Years Ago
Author
Message
Nevron Support
Posted 11 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi,

This is a complete working sample that substitudes the print preview command.

using System;

using System.Windows.Forms;

using Nevron.Diagram;

using Nevron.Diagram.Extensions;

using Nevron.Diagram.WinForm;

using Nevron.Diagram.WinForm.Commands;

namespace WindowsFormsApplication15

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

NDrawingView view = new NDrawingView();

view.Dock = DockStyle.Fill;

Controls.Add(view);

view.Document = new NDrawingDocument();

NDiagramCommandBarsManager manager = new NDiagramCommandBarsManager();

manager.ParentControl = this;

manager.View = view;

MyPrintPreviewCommand.UpdateCmdBarManager(manager);

}

}

public class MyPrintPreviewCommand : NPrintPreviewCommand

{

public override void Execute()

{

if (Commander == null)

return;

NDrawingDocument document = Commander.Document;

if (document == null)

return;

NPrintManager manager = new NPrintManager(document);

manager.Layout = Nevron.GraphicsCore.PagedLayout.FitToPages;

try

{

manager.ShowPrintPreview();

}

catch (Exception ex)

{

MessageBox.Show("Failed to show the print preview dialog. Exception was: " + ex.Message);

}

}

public static void UpdateCmdBarManager(NDiagramCommandBarsManager cmdBarManager)

{

NDiagramCommand oldCommand = cmdBarManager.Commander.Commands.GetCommandFromId((int)DiagramCommand.PrintPreview);

cmdBarManager.Commander.Commands.Remove(oldCommand);

cmdBarManager.Commander.Commands.Add(new MyPrintPreviewCommand());

cmdBarManager.Recreate();

}

}

}

Parhaps there is another reason for the code not to work in your enviroment.

 



Best Regards,
Nevron Support Team



Trond Borg
Posted 11 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 7, Visits: 1
I was able to workaround but am now getting another exception.

The workaround is;

public static void UpdateCmdBarManager(NDiagramCommandBarsManager cmdBarManager)
{
NDiagramCommand oldCommand = null;
foreach (NDiagramCommand command in cmdBarManager.Commander.Commands)
if (command.Id == (int) DiagramCommand.PrintPreview)
oldCommand = command;
if (oldCommand != null)
cmdBarManager.Commander.Commands.Remove(oldCommand);
cmdBarManager.Commander.Commands.Add(new MyPrintPreviewCommand());
cmdBarManager.Recreate();
}

However, now I am getting an exception: "Arithmetic operation resulted in an overflow." when executing manager.ShowPrintPreview();

Trond Borg
Posted 11 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 7, Visits: 1
Unfortunately this is not working... when calling the UpdateCmdBarManager, it throws an exception on the first line:
"NDiagramCommand oldCommand = cmdBarManager.Commander.Commands.GetCommandFromId((int)DiagramCommand.PrintPreview);"

The errormessage is:

"Item has already been added. Key in dictionary: '5' Key being added: '5'"

Seems very strange as I would think the GetCommandFromId does nothing, but fetch the command...

Nevron Support
Posted 11 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

The print preview diagram command executes this code:

if (Commander == null)
 return;

NDrawingDocument document = Commander.Document;
if (document == null)
 return;

NPrintManager manager = new NPrintManager(document);
try
{
 manager.ShowPrintPreview();
}
catch (Exception ex)
{
 MessageBox.Show("Failed to show the print preview dialog. Exception was: " + ex.Message);
}

So as you can see you need to override the command in order to preselect any settings of the newly created print manager, that is created each time you click the PrintPreview command, like this:

public class MyPrintPreviewCommand : NPrintPreviewCommand
{
    public override void Execute()
    {
        if (Commander == null)
            return;

        NDrawingDocument document = Commander.Document;
        if (document == null)
            return;

        NPrintManager manager = new NPrintManager(document);
        manager.Layout = Nevron.GraphicsCore.PagedLayout.FitToPages;
        try
        {
            manager.ShowPrintPreview();
        }
        catch (Exception ex)
        {
            MessageBox.Show("Failed to show the print preview dialog. Exception was: " + ex.Message);
        }
    }

    pubilc static void UpdateCmdBarManager(NDiagramCommandBarsManager cmdBarManager)
    {
        NDiagramCommand oldCommand = cmdBarManager.Commander.Commands.GetCommandFromId((int)DiagramCommand.PrintPreview);
        cmdBarManager.Commander.Commands.Remove(oldCommand);
        cmdBarManager.Commander.Commands.Add(new MyPrintPreviewCommand());

        cmdBarManager.Recreate();
    }
}

Last thing to do is to invoke the UpdateCmdBarManager by passing a reference to your command bars manager.

 



Best Regards,
Nevron Support Team



Trond Borg
Posted 11 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 7, Visits: 1
What I was trying to do was to autoselect "Fit To Pages" in the print preview dialog that pops up from the standard toolbar. That didnt work with this code either.

Is that not possible?

Mohamed Koker
Posted 11 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 2, Visits: 1
Please try the following:


NPrintManager printManager = new NPrintManager(document);
printManager.Layout = PagedLayout.FitToPages;
printManager.PageColumns = 1;
printManager.PageRows = 1;


Trond Borg
Posted 11 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 7, Visits: 1
I am having the same issue, and would also appreciate a fix for this

Mohamed Koker
Posted 11 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 2, Visits: 1
Hi All,

I upgraded to version 12.12.17.12 recently and found the following code no longer compiles:

NPrintManager printManager = new NPrintManager(document);
printManager.PrintOnSinglePage = true;

I would be grateful for any help in getting this code to compile.

Thanks in advance

-Mohamed



Similar Topics


Reading This Topic