PageRenderTime 18ms CodeModel.GetById 10ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/Visual Studio 2008/VBWinFormPrinting/MainForm.vb

#
Visual Basic | 53 lines | 21 code | 10 blank | 22 comment | 0 complexity | 3a6cdf346fe400b10e7a929367444e6f MD5 | raw file
 1'************************************* Module Header **************************************\
 2' Module Name:  MainForm.vb
 3' Project:      VBWinFormPrinting
 4' Copyright (c) Microsoft Corporation.
 5' 
 6' The Printing sample demonstrates how to do standard print job in Windows Forms Application.
 7' 
 8' This source is subject to the Microsoft Public License.
 9' See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
10' All other rights reserved.
11' 
12' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
13' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
14' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
15'******************************************************************************************/
16
17Public Class MainForm
18    Inherits Form
19
20    Public Sub New()
21        MyBase.New()
22        InitializeComponent()
23    End Sub
24
25    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
26        ' The example assumes your form has a Button control, 
27        ' a PrintDocument component named myDocument, 
28        ' and a PrintPreviewDialog control. 
29
30        ' Handle the PrintPage event to write the print logic.
31        AddHandler PrintDocument1.PrintPage, AddressOf Me.printDocument1_PrintPage
32
33        ' Specify a PrintDocument instance for the PrintPreviewDialog component.
34        Me.PrintPreviewDialog1.Document = Me.PrintDocument1
35    End Sub
36
37    Private Sub printDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
38        ' Specify what to print and how to print in this event handler.
39        ' The follow code specify a string and a rectangle to be print 
40
41        Dim f As Font = New Font("Vanada", 12)
42        Dim br As SolidBrush = New SolidBrush(Color.Black)
43        Dim p As Pen = New Pen(Color.Black)
44        e.Graphics.DrawString("This is a text.", f, br, 50, 50)
45
46        e.Graphics.DrawRectangle(p, 50, 100, 300, 150)
47    End Sub
48
49    Private Sub btnPrint_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPrint.Click
50        Me.PrintPreviewDialog1.ShowDialog()
51    End Sub
52    
53End Class