Results 1 to 3 of 3

Thread: printer.print?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Location
    Florida, US
    Posts
    72

    printer.print?

    what is the .net equivilent printer.print, printer.enddoc, etc.?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: printer.print?

    Here is an example from the help file. The PrintDocument object is the equilivalent.
    VB Code:
    1. Public Class PrintingExample
    2.     Inherits System.Windows.Forms.Form
    3.     Private components As System.ComponentModel.Container
    4.     Private printButton As System.Windows.Forms.Button
    5.     Private printFont As Font
    6.     Private streamToPrint As StreamReader
    7.    
    8.     Public Sub New()
    9.         ' The Windows Forms Designer requires the following call.
    10.         InitializeComponent()
    11.     End Sub    
    12.    
    13.     ' The Click event is raised when the user clicks the Print button.
    14.     Private Sub printButton_Click(sender As Object, e As EventArgs)
    15.         Try
    16.             streamToPrint = New StreamReader("C:\My Documents\MyFile.txt")
    17.             Try
    18.                 printFont = New Font("Arial", 10)
    19.                 Dim pd As New PrintDocument()
    20.                 AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
    21.                 pd.Print()
    22.             Finally
    23.                 streamToPrint.Close()
    24.             End Try
    25.         Catch ex As Exception
    26.             MessageBox.Show(ex.Message)
    27.         End Try
    28.     End Sub    
    29.    
    30.     ' The PrintPage event is raised for each page to be printed.
    31.     Private Sub pd_PrintPage(sender As Object, ev As PrintPageEventArgs)
    32.         Dim linesPerPage As Single = 0
    33.         Dim yPos As Single = 0
    34.         Dim count As Integer = 0
    35.         Dim leftMargin As Single = ev.MarginBounds.Left
    36.         Dim topMargin As Single = ev.MarginBounds.Top
    37.         Dim line As String = Nothing
    38.        
    39.         ' Calculate the number of lines per page.
    40.         linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)
    41.        
    42.         ' Print each line of the file.
    43.         While count < linesPerPage
    44.             line = streamToPrint.ReadLine()
    45.             If line Is Nothing Then
    46.                 Exit While
    47.             End If      
    48.             yPos = topMargin + count * printFont.GetHeight(ev.Graphics)
    49.             ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, New StringFormat())
    50.             count += 1
    51.         End While
    52.        
    53.         ' If more lines exist, print another page.
    54.         If Not (line Is Nothing) Then
    55.             ev.HasMorePages = True
    56.         Else
    57.             ev.HasMorePages = False
    58.         End If
    59.     End Sub
    60.      
    61.    
    62.     ' The Windows Forms Designer requires the following procedure.
    63.     Private Sub InitializeComponent()
    64.         Me.components = New System.ComponentModel.Container()
    65.         Me.printButton = New System.Windows.Forms.Button()
    66.        
    67.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    68.         Me.ClientSize = New System.Drawing.Size(504, 381)
    69.         Me.Text = "Print Example"
    70.        
    71.         printButton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
    72.         printButton.Location = New System.Drawing.Point(32, 110)
    73.         printButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat
    74.         printButton.TabIndex = 0
    75.         printButton.Text = "Print the file."
    76.         printButton.Size = New System.Drawing.Size(136, 40)
    77.         AddHandler printButton.Click, AddressOf printButton_Click
    78.        
    79.         Me.Controls.Add(printButton)
    80.     End Sub
    81.  
    82.     ' This is the main entry point for the application.    
    83.     Public Shared Sub Main()
    84.         Application.Run(New PrintingExample())
    85.     End Sub
    86.  
    87. End Class
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Location
    Florida, US
    Posts
    72

    Re: printer.print?

    thanks, this should work

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width