Print with an Inputted TextBox using VB.NET

This tutorial will teach you how to create a program that creates a printing of textbox using vb.net. Now, let's start this tutorial! 1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 2. Next, add Button for printing named "bnprint", a textbox named "tx1", .a PrintDialog, and PrintDocument1. You must design your interface like this: output 3. Now, let's do the coding. Import the printing library first.
  1. Imports System.drawing.printing
Then we will code on passing the textbox that you have inputted on the printing. We will use the PrintPage Event of the PrintDocument control.
  1.     Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
  2.         e.Graphics.DrawString(txt1.Text, New Font("Arial", 40,FontStyle.Bold), Brushes.Black, 150, 125)
  3.     End Sub
Lastly, we will code for the printing of the textbox. Here is it:
  1.     Private Sub bnprint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnprint.Click
  2.         PrintDialog1.Document = PrintDocument1
  3.  
  4.         Dim result As DialogResult = PrintDialog1.ShowDialog()
  5.  
  6.         If result = Windows.Forms.DialogResult.OK Then
  7.             PrintDocument1.Print()
  8.         End If
  9.  
  10.     End Sub

Output:

output For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Add new comment