Print contents of WinForms Application using C# and VB.Net

Print contents of WinForms Application using C# and VB Net
Hello friend’s in this tutorial I’ll show you how to Print contents of WinForms Application using C# and VB Net
Create new windows Form application in visual studio. follow the steps
Design your form according to your requirement
add Button for Print the content of winforms app.
add printPreviewDialog and printDocument to form from toolbox

Add the Code below in form.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace print_Windows_Form { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'hR_Management_systemDataSet3.advertisment' table. You can move, or remove it, as needed. // this.advertismentTableAdapter.Fill(this.hR_Management_systemDataSet3.advertisment); } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.Graphics.DrawImage(bitmap, 0, 0); } Bitmap bitmap; private void button1_Click(object sender, EventArgs e) { Panel panel = new Panel(); this.Controls.Add(panel); Graphics graphics = panel.CreateGraphics(); Size size = this.ClientSize; bitmap = new Bitmap(size.Width, size.Height, graphics); graphics = Graphics.FromImage(bitmap); Point point = PointToScreen(panel.Location); graphics.CopyFromScreen(point.X, point.Y, 0, 0, size); printPreviewDialog1.Document = printDocument1; printPreviewDialog1.ShowDialog(); } } }
Video tutorial
Thank you for reading this article. Please don’t forget to subscribe our official YouTube Channel RashiCode