Windows Forms: Printing Text example in a Windows Form using C#
By FoxLearn 5/23/2017 9:07:55 PM 12.62K
Printing Text example in a Windows Form using C#
Step 1: Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "PrintText" and then click OK
Step 2: Design your form as below
You need to add a PrintDocument, PrintPreviewDialog to your form
Step 3: Add code to handle your form
using System; using System.Drawing; using System.Windows.Forms; namespace PrintText { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { //Draw text to your document e.Graphics.DrawString(txtValue.Text, new Font("Times New Roman", 14, FontStyle.Bold), Brushes.Black, new PointF(100, 100)); } private void Print_Click(object sender, EventArgs e) { //Open print dialog if (printPreviewDialog1.ShowDialog() == DialogResult.OK) printDocument1.Print(); } } }
VIDEO TUTORIALS
- How to Use Form Load and Button click Event in C#
- How to use Advanced Filter DataGridView in C#
- How to use TagListControl in C#
- How to use Error Provider in C#
- How to Drag and Drop controls in C#
- How to Create a Random Password Generator in C#
- How to make an Application auto run on Windows startup in C#
- How to Create a Wait Form Dialog in C#
Categories
Popular Posts
C# Tutorial
07/20/2024
How to Download Microsoft SQL Server
06/22/2024
What is ARM architecture?
04/01/2024