Wrox Programmer Forums
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 1st, 2005, 07:21 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anubhav.kumar
Default Printer in VB.net

I want to know what is equivalent to Printer Object (VB6.0)
I want to access the printer directly without using print dialog or prindocument controls.

Thanks in advance for guidance

Anubhav Kumar
__________________
Anubhav Kumar
http://anubhavtimepass.blogspot.com/
 
Old February 1st, 2005, 09:23 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Printing is completely different in VB.Net to VB6. The nearest thing you have to the printer object is the PrintDocument class, that represents the connection between an app and a printer.

It raises an event for each page to be printed, so you need to handle this event and supply the text/graphics to be printed.

The other classes you'll need are in System.Drawing.Printing

Example:

Drop a textbox, button and PrintDocument component onto a new form.

in the button click event handler put

Code:
PrintDocument1.Print
Then add the following code at the bottom of the form class

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

    ' create a new font to print with...
    Dim fnt As New Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Point)

    ' print the text from the text box...
    e.Graphics.DrawString(TextBox1.Text, fnt, Brushes.Black, 0, 0)

    ' end printing by indicating there are no more pages...
    e.HasMorePages = False

End Sub
 
Old September 30th, 2008, 09:42 AM
Registered User
 
Join Date: Sep 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Hi,

Can i use eventhandler instead of a function?

Example:
 Private Sub PrintColumn(ByRef ColumnNumber As Short, ByRef pTask As jFlowX.jFlowTask)
        Try
            Select Case ColumnNumber
                Case COLUMN_STATUS
                    If pTask.Status = "WANew" Then
                        'UPGRADE_ISSUE: Printer object was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6B85A2A7-FE9F-4FBE-AA0C-CF11AC86A305"'
                        'UPGRADE_ISSUE: Printer method Printer.Print was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="076C26E5-B7A9-4E77-B69C-B4448DF39E58"'
                        Printer.Print(GetResString(3036))
                    ElseIf pTask.Status = "WADone" Then
                        'UPGRADE_ISSUE: Printer object was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6B85A2A7-FE9F-4FBE-AA0C-CF11AC86A305"'
                        'UPGRADE_ISSUE: Printer method Printer.Print was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="076C26E5-B7A9-4E77-B69C-B4448DF39E58"'
                        Printer.Print(GetResString(3037))
                    ElseIf pTask.Status = "WAPend" Then
                        'UPGRADE_ISSUE: Printer object was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6B85A2A7-FE9F-4FBE-AA0C-CF11AC86A305"'
                        'UPGRADE_ISSUE: Printer method Printer.Print was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="076C26E5-B7A9-4E77-B69C-B4448DF39E58"'
                        Printer.Print(GetResString(3038))
                    ElseIf pTask.Status = "WADue" Then
                        'UPGRADE_ISSUE: Printer object was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6B85A2A7-FE9F-4FBE-AA0C-CF11AC86A305"'
                        'UPGRADE_ISSUE: Printer method Printer.Print was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="076C26E5-B7A9-4E77-B69C-B4448DF39E58"'
                        Printer.Print(GetResString(3039))
                    End If
                Case COLUMN_TASK
                    'UPGRADE_ISSUE: Printer object was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6B85A2A7-FE9F-4FBE-AA0C-CF11AC86A305"'
                    'UPGRADE_ISSUE: Printer method Printer.Print was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="076C26E5-B7A9-4E77-B69C-B4448DF39E58"'
                    Printer.Print(pTask.Name)
                Case COLUMN_WORKFLOW
                    'UPGRADE_ISSUE: Printer object was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6B85A2A7-FE9F-4FBE-AA0C-CF11AC86A305"'
                    'UPGRADE_ISSUE: Printer method Printer.Print was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="076C26E5-B7A9-4E77-B69C-B4448DF39E58"'
                    Printer.Print(pTask.workflow)
                Case COLUMN_STARTED
                    'UPGRADE_WARNING: IsEmpty was upgraded to IsNothing and has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
                    If Not IsNothing(pTask.Started) Then
                        ' Printer.CurrentX = Printer.CurrentX - Printer.TextWidth(pTask.Started)
                        'UPGRADE_ISSUE: Printer object was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6B85A2A7-FE9F-4FBE-AA0C-CF11AC86A305"'
                        'UPGRADE_ISSUE: Printer method Printer.Print was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="076C26E5-B7A9-4E77-B69C-B4448DF39E58"'
                        Printer.Print(CStr(pTask.Started))
                    End If
                Case COLUMN_COMPLETED
                    'UPGRADE_WARNING: IsEmpty was upgraded to IsNothing and has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
                    If Not IsNothing(pTask.Completed) Then
                        'UPGRADE_ISSUE: Printer object was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6B85A2A7-FE9F-4FBE-AA0C-CF11AC86A305"'
                        'UPGRADE_ISSUE: Printer method Printer.Print was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="076C26E5-B7A9-4E77-B69C-B4448DF39E58"'
                        Printer.Print(CStr(pTask.Completed))
                    End If
                Case COLUMN_DUE
                    'UPGRADE_WARNING: IsEmpty was upgraded to IsNothing and has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
                    If Not IsNothing(pTask.DueDate) Then
                        'UPGRADE_ISSUE: Printer object was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6B85A2A7-FE9F-4FBE-AA0C-CF11AC86A305"'
                        'UPGRADE_ISSUE: Printer method Printer.Print was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="076C26E5-B7A9-4E77-B69C-B4448DF39E58"'
                        Printer.Print(CStr(pTask.DueDate))
                    End If
                Case COLUMN_PRIORITY
                    Select Case pTask.Priority
                        Case "1"
                            'UPGRADE_ISSUE: Printer object was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6B85A2A7-FE9F-4FBE-AA0C-CF11AC86A305"'
                            'UPGRADE_ISSUE: Printer method Printer.Print was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="076C26E5-B7A9-4E77-B69C-B4448DF39E58"'
                            Printer.Print(GetResString(3032))
                        Case "2"
                            'UPGRADE_ISSUE: Printer object was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6B85A2A7-FE9F-4FBE-AA0C-CF11AC86A305"'
                            'UPGRADE_ISSUE: Printer method Printer.Print was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="076C26E5-B7A9-4E77-B69C-B4448DF39E58"'
                            Printer.Print(GetResString(3033))
                        Case "3"
                            'UPGRADE_ISSUE: Printer object was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6B85A2A7-FE9F-4FBE-AA0C-CF11AC86A305"'
                            'UPGRADE_ISSUE: Printer method Printer.Print was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="076C26E5-B7A9-4E77-B69C-B4448DF39E58"'
                            Printer.Print(GetResString(3034))
                    End Select
                Case COLUMN_ASSIGNEE
                    'UPGRADE_ISSUE: Printer object was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6B85A2A7-FE9F-4FBE-AA0C-CF11AC86A305"'
                    'UPGRADE_ISSUE: Printer method Printer.Print was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="076C26E5-B7A9-4E77-B69C-B4448DF39E58"'
                    Printer.Print(pTask.Assignee)
                Case COLUMN_COMMENT
                    If RTrim(pTask.Comment) <> "" Then
                        'UPGRADE_ISSUE: Printer object was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6B85A2A7-FE9F-4FBE-AA0C-CF11AC86A305"'
                        'UPGRADE_ISSUE: Printer method Printer.Print was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="076C26E5-B7A9-4E77-B69C-B4448DF39E58"'
                        Printer.Print(pTask.Comment)
                    End If
            End Select
        Catch ex As Exception
            Dim rethrow As Boolean
            rethrow = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If rethrow Then
                Throw
            End If
        End Try
    End Sub

The above function is called in another function and it is using the printer method.
Please let me know how can i replace event handler instead of this function.






Similar Threads
Thread Thread Starter Forum Replies Last Post
install printer by vb.net mvenkatesan Visual Studio 2005 0 September 6th, 2007 12:47 AM
Help with Printer Object in VB aniljacob VB How-To 1 March 23rd, 2006 03:22 PM
Printer Object in VB.NET ashu_from_india General .NET 1 March 8th, 2006 07:16 PM
Printing problem dot matrix printer using VB.Net [email protected] Crystal Reports 0 February 21st, 2006 11:29 AM
VB Printer.print command Hiddenattractor Java GUI 3 December 30th, 2003 09:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.