Presentation is loading. Please wait.

Presentation is loading. Please wait.

Printer & Dialog boxes Engr. Faisal ur Rehman CE-105T Spring 2007.

Similar presentations


Presentation on theme: "Printer & Dialog boxes Engr. Faisal ur Rehman CE-105T Spring 2007."— Presentation transcript:

1 Printer & Dialog boxes Engr. Faisal ur Rehman CE-105T Spring 2007

2 Printer In GDI+, we have the namespace of System.Drawing.Printing for printing. For printing, we need: –PrintDocument Class –Print method –Graphics Property –StreamReader –DrawString –PrintController –PreviewPrintController –PrintPreviewControl

3 Printer Following dialog boxes are also used: –PrintDialog –PageSetupDialog –PrintPreviewDialog

4 Explanation PrintDocument Class: Defines a reusable object that sends output to a printer. Print method: This method is called by PrintDocument to print document Graphics Property: Specify the output to print. StreamReader reads one line at a time from the stream DrawString method is used to draw the line in the graphics object. PrintController controls how a PrintDocument is printed. It has following methods: –OnStartPrint, OnEndPrint, OnStartPage, and OnEndPage PreviewPrintController and PrintPreviewControl controls the preview of Document

5 Printing Un-Formated Text Use PrintDocument1 Control and Pass its Print Method For facilitation, add PrintDialog1 and attach its Document to PrintDocument1 PrintPreviewDialog1 will add preview while PageSetupDialog1 will add page setup functionality

6 Printing Un-Formated Text During a print, an event of pdoc_PrintPage is fired, which is attached to PrintDocument1 During this event, following setting is done: 1.Font 2.DefaultPageSettings 3.Format for print, which is rectangular 4.And Check for more pages to Print

7 Printing Graphics Following namespaces are used: –System.ComponentModel –System.Collections –System.Drawing –System.Drawing.Printing –System.Resources –System.Windows.Forms

8 Printing Graphics Declare PrintDocument and add EventHandler of PrintPage which will pass during Print method of PrintDocument In event picture from resource is printed by DrawImage method

9 Q & A Define the following: –PrintDocument Class –Print method –Graphics Property –StreamReader –DrawString –PrintController –PreviewPrintController –PrintPreviewControl Write the procedure for printing text files (unformatted) Write the procedure for printing graphics

10 Dialog Box Secondary window opened from main window to display or get information from user is called a dialog box In simple terms, a dialog box is a form with its FormBorderStyle enumeration property set to FixedDialog. Dialog boxes are used to interact with the user and retrieve information. There are two categories: –Modal –Modeless.

11 Dialog Box Modal dialog box commonly prevents users from activating other windows while it remains open. A modeless dialog box, on the other hand, does not prevent users from activating other windows while it is open.

12 Types Example of dialog boxes falls in to three categories: –Message Boxes –Common Dialog Boxes –Custom Dialog Boxes

13 Types Message box is a simple dialog box that can be used to both display information and allow users to make a decision. Common dialog boxes are: –OpenFileDialog –SaveFileDialog –PrintDialog Custom Dialog box is more complex than a message box and is not supported by the common dialog boxes, you need to create your own.

14 Example of Open Dialog Box Private Sub open() Dim myStream As IO.Stream Dim openFileDialog1 As New OpenFileDialog() openFileDialog1.InitialDirectory = "c:\" openFileDialog1.Filter = "MPL Input Files|*.txt" openFileDialog1.FilterIndex = 2 openFileDialog1.RestoreDirectory = True If openFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then myStream = openFileDialog1.OpenFile() If Not (myStream Is Nothing) Then ' Insert code to read the stream here. Dim path As String = "" Dim text As String = "" path = openFileDialog1.FileName text = My.Computer.FileSystem.ReadAllText(path) sInputFile = text myStream.Close() End If End Sub

15 Example of Open Dialog Box Friend Sub save() Dim saveFileDialog1 As New SaveFileDialog() saveFileDialog1.Filter = "Text Files|*.txt" saveFileDialog1.Title = "Save a Text File" saveFileDialog1.ShowDialog() If saveFileDialog1.FileName <> "" Then Dim Path As String = "" Dim Text As String = "" Path = saveFileDialog1.FileName Text = sInputFile My.Computer.FileSystem.WriteAllText(Path, Text, True) End If End Sub

16 Example of Font Dialog Private Sub button1_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Button1.Click FontDialog1.ShowColor = True FontDialog1.Font = TextBox1.Font FontDialog1.Color = TextBox1.ForeColor If FontDialog1.ShowDialog() <> _ Windows.Forms.DialogResult.Cancel Then TextBox1.Font = FontDialog1.Font TextBox1.ForeColor = FontDialog1.Color End If End Sub

17 Example of Color Dialog Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click Dim MyDialog As New ColorDialog() MyDialog.AllowFullOpen = False MyDialog.ShowHelp = True MyDialog.Color = TextBox1.ForeColor If (MyDialog.ShowDialog() = _ Windows.Forms.DialogResult.OK) Then TextBox1.BackColor = MyDialog.Color End If End Sub

18 Q & A Define a dialog box What are categories and types Name some dialog boxes Write example code of a dialog box

19 T H A N K S


Download ppt "Printer & Dialog boxes Engr. Faisal ur Rehman CE-105T Spring 2007."

Similar presentations


Ads by Google