using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Drawing.Printing; namespace f_print { public partial class Form1 : Form { struct MarginsBox { public float Top; public float Left; public float Bottom; public float Right; public float Width; public float Height; } Graphics gfx; Bitmap printmap = new Bitmap(850, 1100); MarginsBox m = new MarginsBox(); Font f; // Font object, to store fonts PrintDocument pd = new PrintDocument(); // Red line to the printer float dpi = 256;//128; // Dots Per Inch public Form1() { InitializeComponent(); Start(); } public void Start() { printmap.SetResolution(dpi, dpi); // Set the resolution of our paper m.Top = 1 * dpi; // Set a 1' margin, from the top m.Left = 1.25f * dpi; // Set a 1.25' margin, from the left m.Bottom = printmap.Height - m.Top; // 1', from the bottom m.Right = printmap.Width - m.Left; // 1.25', from the right m.Width = printmap.Width - (m.Left * 2); // Get the width of our working area m.Height = printmap.Height - (m.Top * 2); // Get the height of our working area gfx = Graphics.FromImage(printmap); // Transfer the bitmap into canvas f = new Font("Verdana", 12); // set the font to Verdana, 12 gfx.DrawString("Printing Test; Printing Test; Printing Test; Printing Test;", f, Brushes.Black, new RectangleF(m.Left, m.Top, m.Width, m.Height)); // Our text, put it on the canvas pd.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage); pd.DefaultPageSettings.Color = true; // We want to print in color pd.Print(); // Print try { this.FormBorderStyle = FormBorderStyle.Fixed3D; this.Name = "frmPrint"; // Our form name this.Text = "GCW - Print"; this.MaximizeBox = false; // We can't maximize this.Size = new Size(400, 400); // Form size this.Show(); // Show the form } catch (ObjectDisposedException) { } } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.Graphics.DrawImage(pictureBox1.Image, new Point(0, 0)); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)