Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I'm reading text from file and then I want to print it to printer with formatting.I already read article printing text directly to printer from vb.net[^] But after reading this I added to code but it shows error as "'Me' is not valid within a Module"

Need help asap !

Thanks.

What I have tried:

Public Sub prt(ByVal text As String, ByVal printer As String)
        TextToBePrinted = text
        Dim prn As New Printing.PrintDocument
        Using (prn)
            prn.PrinterSettings.PrinterName = printer
            AddHandler prn.PrintPage,
               AddressOf Me.PrintPageHandler
            prn.Print()
            RemoveHandler prn.PrintPage,
               AddressOf Me.PrintPageHandler
        End Using
    End Sub

    Private Sub PrintPageHandler(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs)
        Dim myFont As New Font("Courier New", 9)
        args.Graphics.DrawString(TextToBePrinted,
           New Font(myFont, FontStyle.Regular),
           Brushes.Black, 50, 50)
    End Sub
Posted
Updated 8-Feb-17 21:27pm

Quote:
I can't find an algorithm that solves this problem in O(n). Do you have any idea?

The message tells you that Me in
VB
AddressOf Me.PrintPageHandler

is unknown.
 
Share this answer
 
Write
AddressOf PrintPageHandler
instead of
AddressOf Me.PrintPageHandler


I'm not that into VB.NET anymore, but as long as i know, a module was the kind of thing you can't create an instace of. It is more like a container.

You can only use Me if you are in a Claas
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900