why is vb.net printing so difficult?

Hi,

I have loads of VB6 apps I am trying to migrate to VB.net and the biggest problem I have is that printer.print has no equivalent in vb.net

Can anyone tell me a simple way to print in dot net

Thanks



Answer this question

why is vb.net printing so difficult?

  • C0venant13

    Hi There

    args.Graphics.DrawString("HelloWorld With A Printer", New Font("Arial", 20, FontStyle.Bold), Brushes.Black, 150, 125)

    Is About Intuitive as a Princess Kissing a Frog..... They Don’t Do that Anymore...... The OOP Mission was Lost Somewhere...... Show me An OOP language with Statements like This and I’m Gone......

    Printer.Printline."Fish".........

    Diskdrive.Writetext."Dog","Cat"......

    Monitor.Display."Hello Real World".....

    Etc......

    Cheers
    Bronco Billy
    "Beer and Fast Women are Ok... No Cigarettes or Hard Liquor Allowed It’s All Rock And Roll"


  • Merten1982

    You still have to tell it where you want to print it, what font and what color: how would you address that What about drawing images, graphics and charts

    Regardless, the drawing functions are ther same for both printer ad screen (picture box, button, form, control, etc.) and eliminates a lot of the esoteric nature of Classic VB, as well as using the Win32 API (loading pens and brushes; destroying handles, except when it's a system brush, etc.).

    With that one line of code, you have an object, you are taking the graphical portion of that object (a canvas), and you are going to draw text on it. You tell it the text you want, the style, the color and where. Pretty straight forward, really. In one line, as well.

    As a RAD tool for graphical applications, classic VB was pretty poor to develop a viable application with the native VB code: the Win32 API was the way to go. Now we have a native environment with decent drawing functions. Sounds like a winner of a Rapid Application Development tool, and a great step up from classic VB.



  • Engage

    Have it your way, Billy.

     



  • mkassa

    My greatest problem is working out where page breaks go when I have variable amounts of text with different font sizes to print and keeping track of what has been printed and what hasn't.  Still hope My.Printer comes back as this would make simple printing of text much easier.
  • ERK

    That ok with fixed strings "yada..yada.." but what to do when we have a neatly formated datagridview of say a balance statement and I need a print out of that....I am having a real hell now
  • rabbitoh

     vbman wrote:

    Impossible is about right.

    I just can't see what to type to make something come out on paper, and I have written some neat VB stuff (IMHO) in th epast but this dot net thing has me stumped. Am I missing something or is nobody printing anymore

    Maybe we have finally reached the holy grail of the paperless office by MS removing the ability to print.

    Seriously though, can anyone point me at a print command

    Hi There

    If You want to Old Fashion and Pump out Hard Copy.... Shell Out $800 and Buy the Pro edition... Slam Your Hard Data in a Database and use the Report Writer To Kill Trees.....Is This Crystal Clear.....

    Cheers
    Bronco Billy
    "Beer and Fast Women are Ok... No Cigarettes or Hard Liquor Allowed suppression


  • James Crowley

    Printing is difficult in VB.Net in my opinion, especially with multiple pages involving text , different fonts and sizes, images and working out where page breaks go.

    My.Printer looked terrific but it was axed from the beta versions, hopefully it will return one day.  I am off to buy the full Visual Studio product as its report control looks to be the answer for me. 

    Image posted at http://www.accessgp.com/reportexample.JPG - not my work.  I am running VB Express with the report viewer installed - I can look at them but cant create them.

     

    GS


  • Gayeshan

    Impossible is about right.

    I just can't see what to type to make something come out on paper, and I have written some neat VB stuff (IMHO) in th epast but this dot net thing has me stumped. Am I missing something or is nobody printing anymore

    Maybe we have finally reached the holy grail of the paperless office by MS removing the ability to print.

    Seriously though, can anyone point me at a print command


  • Marcos Nunes

    It's not, really: just different from VB6. Much nicer, and controllable.

    Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        Dim prn As New
    Printing.PrintDocument
        ' Select the PDF Printer
        prn.PrinterSettings.PrinterName =
    "pdf995"
        ' Handle the page events
        AddHandler prn.PrintPage, AddressOf Me
    .PrintPageHandler
        ' Do the print (Printing handled by the print page handler)
        prn.Print()
        ' Remove the page handler
        RemoveHandler prn.PrintPage, AddressOf Me
    .PrintPageHandler
    End
    Sub
    Private Sub PrintPageHandler(ByVal sender As Object, ByVal args As
    Printing.PrintPageEventArgs)
        Static i As Integer
    = 0
        i = i + 1
        ' Print a line on this page
        args.Graphics.DrawString("Printed a Line on page " & i.ToString, New Font(Me
    .Font, FontStyle.Regular), Brushes.Black, 50, 50)
        ' Have we printed enough pages
        If i >= 5
    Then
            ' Done all the pages
            i = 0
            args.HasMorePages =
    False
        Else
            ' Not finished, yet
            args.HasMorePages =
    True
       End
    If
    End Sub

    This'll print 5 pages with a line of text on each page. Each page is 'drawn' in the Page Event Handler, just as if it was a graphic canvas (the args.Graphics is the graphical canvas).

    That should point you in the right direction. Start looking at the Printing.PrintDocument namespace.



  • Mark Vickers

    Hi There SJW

    Thanks A Lot......

    Here’ a Variation of the Same Theme.....Needs a Button1 on a Form.... It ain’t Pretty But It Works Here......

    Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim prn As New Printing.PrintDocument

    prn.PrinterSettings.PrinterName.ToString()

    AddHandler prn.PrintPage, AddressOf Me.PrintPageHandler

    prn.Print()

    RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHandler

    End Sub

    Private Sub PrintPageHandler(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs)

    args.Graphics.DrawString("HelloWorld With A Printer", New Font("Arial", 20, FontStyle.Bold), Brushes.Black, 150, 125)

    End Sub

    Cheers
    Bronco Billy
    "Beer and Fast Women are Ok... No Cigarettes or Hard Liquor Allowed suppression


  • rogerdubie

    Hi There


    You still have to tell it where you want to print it, what font and what color: how would you address that What about drawing images, graphics and charts

    Printer.Printline."Fish"......... See all the ..... They are Properties.....

    Printer.Printline."Fish".Prop1.prop2.prpn......

    All statements in My.New.Language MUST be Henny Youngman’s.... This Language would be on TOP of the Existing VB Language As the Net.Framework is UNDER the Existing VB Language....... Which means One can Pick and Choose Cafeteria Style........ How about this One Liner.......

    For.i=1.prop1.prop2.propn.next

    etc....

    Regardless, the drawing functions are ther same for both printer ad screen (picture box, button, form, control, etc.) and eliminates a lot of the esoteric nature of Classic VB, as well as using the Win32 API (loading pens and brushes; destroying handles, except when it's a system brush, etc.).

    With that one line of code, you have an object, you are taking the graphical portion of that object (a canvas), and you are going to draw text on it. You tell it the text you want, the style, the color and where. Pretty straight forward, really. In one line, as well.

    You Write Well but I count more than One line of Code..... You might be able to unnest them and make one arcane line...... The new VB is Terrific.... The Trouble is It is no more than An Ugly C#.......

    As a RAD tool for graphical applications, classic VB was pretty poor to develop a viable application with the native VB code: the Win32 API was the way to go. Now we have a native environment with decent drawing functions. Sounds like a winner of a Rapid Application Development tool, and a great step up from classic VB.

    Up And Down.......

    Cheers
    Bronco Billy
    "Beer and Fast Women are Ok... No Cigarettes or Hard Liquor Allowed It’s All Rock And Roll"


  • erprashant

    Personally, from what I've played around with, I much prefer this new method to the VB 'classic' way of printing - it was always a pain in the neck to print anything other than text.

  • Ilianato

    So.... I have to ask.....is there anyone who really sees this as an improvement over what we had previously (printer.print strMyText)

     


  • AlainDe

    Hi Stephen,

    Thanks for the useful and very educational answer. I think I can get it down to ten lines instead of the one in VB6, but I'll take your word for it that this is a better way.

    I have printed from my app, now I just need to figure out a replacement for all my old paintpicture and drawbox commands.

    This is a great example of what Forums are for.

    Tom


  • why is vb.net printing so difficult?