Print a String in Windows forms

Posted by Ddd under Windows Forms category on | Points: 40 | Views : 2794
//Print a string

//Take a Button and a PrintDocument on the Form.

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;

namespace WindowsFormsApplication2
public partial class Form5 : Form
public Form5()
private void button1_Click(object sender, EventArgs e)
//First install some Compatible printer

//example:AGFA-AccuSet v52.3
//Start the Printing
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
//code for printing

e.Graphics.DrawString("welcome", this.Font, Brushes.Blue, 10, 20);


// welcome: string will be printed.
//this.Font: the Specifications of the string's Font will be the same
//as those of the Font's Form
//Brushes.Blue: Color of the String
// 10 and 20: x and y coordinates on the page
// where the string will be positioned.


Comments or Responses

Login to post response