PrintUtility 1.0.2

dotnet add package PrintUtility --version 1.0.2                
NuGet\Install-Package PrintUtility -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PrintUtility" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PrintUtility --version 1.0.2                
#r "nuget: PrintUtility, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PrintUtility as a Cake Addin
#addin nuget:?package=PrintUtility&version=1.0.2

// Install PrintUtility as a Cake Tool
#tool nuget:?package=PrintUtility&version=1.0.2                
using PrintUtility;

public partial class PrintUtilityTester : Form
{
    public PrintUtilityTester()
    {
        /** Sample for printing 12 sides label */

        /** PrintManager only accepts GraphicsUnit.Display or GraphicsUnit.Millimeter */
        PrintManager printManager = new PrintManager(PaperKind.A4, GraphicsUnit.Millimeter);
        Label[] arrayLabel = null;
        string[] arrayImageFileName = null;

        TableLayoutPanel tableLayoutPanel = new TableLayoutPanel()
        {
            Parent = this,
            RowCount = 6,
            ColumnCount = 2,
            Dock = DockStyle.Fill,
            CellBorderStyle = TableLayoutPanelCellBorderStyle.Single,
        };
        for (int i = 0; i < tableLayoutPanel.ColumnCount; i++)
        {
            tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
        }

        for (int j = 0; j < tableLayoutPanel.RowCount; j++)
        {
            tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, (float)100.0 / tableLayoutPanel.RowCount));
        }

        var cellcnt = tableLayoutPanel.ColumnCount * tableLayoutPanel.RowCount;
        arrayLabel = new Label[cellcnt];

        Action<bool> Print = (preview) =>
        {
            printManager.Clear();
            for (int i = 0; i < cellcnt; i++)
            {
                var x = (i % 2 == 1) ? 20 + 83 + 2 : 20;
                var y = i / 2 * 42 + 22;
                var w = 83;
                var h = 42;
                Rectangle r = new Rectangle(x, y, w, h);
                var req = new PrintCommandDrawString(arrayLabel[i].Text, r, SystemInformation.MenuFont.Name, 12);
                printManager.Add(1, req);

                /** For guide (preview only) */
                var reqrect = new PrintCommandDrawRectangle(r, Color.Red) { PreviewOnly = true, };
                printManager.Add(1, reqrect);

                if (!string.IsNullOrEmpty(arrayImageFileName[i]) && System.IO.File.Exists(arrayImageFileName[i]))
                {
                    var image = Image.FromFile(arrayImageFileName[i]);
                    var reqimage = new PrintCommandDrawImage(image, new Point(x, y));
                    printManager.Add(1, reqimage);
                }
            }

            if (preview)
            {
                printManager.Preview();
            }
            else
            {
                printManager.Print();
            }
        };

        for (int i = 0; i < cellcnt; i++)
        {
            var label = new Label()
            {
                Dock = DockStyle.Fill,
            };
            label.ContextMenuStrip = new ContextMenuStrip();
            ToolStripMenuItem toolStripMenuItemInsert = new ToolStripMenuItem() { Text = "Insert text", };
            toolStripMenuItemInsert.Click += (sender, e) =>
            {
                Form f = new Form() { StartPosition = FormStartPosition.CenterScreen, };
                Panel p = new Panel() { Parent = f, Dock = DockStyle.Top, Height = new Button().Height, };
                Button buttonOK = new Button() { Text = "OK", DialogResult = DialogResult.OK, Parent = p, Dock = DockStyle.Right, };
                Button buttonCancel = new Button() { Text = "Cancel", DialogResult = DialogResult.Cancel, Parent = p, Dock = DockStyle.Right, };
                TextBox textBox = new TextBox() { Parent = f, Dock = DockStyle.Top, Multiline = true, Height = 500, };
                f.SizeChanged += (sender2, e2) => { textBox.Height = f.ClientSize.Height - p.Height; };
                f.Shown += (sender2, e2) => { textBox.Focus(); };
                f.ClientSize = new Size(400, 400);
                if (f.ShowDialog() == DialogResult.OK)
                {
                    label.Text = textBox.Text;
                }
            };

            label.ContextMenuStrip.Items.Add(toolStripMenuItemInsert);

            ToolStripMenuItem toolStripMenuItemInsertFromClipboard = new ToolStripMenuItem() { Text = "Insert text from clipboard", };
            toolStripMenuItemInsertFromClipboard.Click += (sender, e) =>
            {
                label.Text = Clipboard.GetText();
            };
            label.ContextMenuStrip.Items.Add(toolStripMenuItemInsertFromClipboard);

            ToolStripMenuItem toolStripMenuItemInsertImage = new ToolStripMenuItem() { Text = "Insert image", };

            var idx = i;

            toolStripMenuItemInsertImage.Click += (sender, e) =>
            {
                var ofd = new OpenFileDialog()
                {
                    InitialDirectory = Application.StartupPath,
                    Filter = "png(*.png;*.jpg)|*.png;*.jpg",
                };

                /** select about 200*200 png ?  */
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    arrayImageFileName[idx] = ofd.FileName;
                }
            };
            label.ContextMenuStrip.Items.Add(toolStripMenuItemInsertImage);

            tableLayoutPanel.Controls.Add(label);
            arrayLabel[i] = label;
        }

        Action reset = () =>
        {
            Array.ForEach(arrayLabel, x => x.Text = string.Empty);
            arrayImageFileName = new string[cellcnt];
        };
        reset();

        ToolStrip toolStrip = new ToolStrip() { Dock = DockStyle.Top, Parent = this, };
        ToolStripButton toolStripButtonClearAll = new ToolStripButton() { Alignment = ToolStripItemAlignment.Right, Text = "Reset", };
        toolStripButtonClearAll.Click += (sender, e) => { reset(); };

        ToolStripButton toolStripButtonPrint = new ToolStripButton() { Alignment = ToolStripItemAlignment.Right, Text = "Print", };
        toolStripButtonPrint.Click += (sender, e) => { Print(false); };
        ToolStripButton toolStripButtonPreview = new ToolStripButton() { Alignment = ToolStripItemAlignment.Right, Text = "Preview", };
        toolStripButtonPreview.Click += (sender, e) => { Print(true); };

        toolStrip.Items.Add(toolStripButtonPrint);
        toolStrip.Items.Add(toolStripButtonPreview);
        toolStrip.Items.Add(toolStripButtonClearAll);

        MenuStrip menuStrip = new MenuStrip() { Parent = this, };
        ToolStripMenuItem toolStripMenuItemFile = new ToolStripMenuItem() { Text = "File", };
        ToolStripMenuItem toolStripMenuItemReset = new ToolStripMenuItem() { Text = "Reset", };
        ToolStripMenuItem toolStripMenuItemPreview = new ToolStripMenuItem() { Text = "Preview", };
        ToolStripMenuItem toolStripMenuItemPrint = new ToolStripMenuItem() { Text = "Print", };
        toolStripMenuItemFile.DropDownItems.Add(toolStripMenuItemReset);
        toolStripMenuItemFile.DropDownItems.Add(new ToolStripSeparator());
        toolStripMenuItemFile.DropDownItems.Add(toolStripMenuItemPreview);
        toolStripMenuItemFile.DropDownItems.Add(toolStripMenuItemPrint);
        menuStrip.Items.Add(toolStripMenuItemFile);

        toolStripMenuItemReset.Click += (sender, e) => { reset(); };
        toolStripMenuItemPreview.Click += (sender, e) => { Print(true); };
        toolStripMenuItemPrint.Click += (sender, e) => { Print(false); };

        ClientSize = new Size(800, 600);
        StartPosition = FormStartPosition.CenterScreen;
        Text = "PrintUtilityTester";
    }
}
Product Compatible and additional computed target framework versions.
.NET Framework net452 is compatible.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 337 4/13/2022