PrinterSettings in VB.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Scott Price
    Recognized Expert Top Contributor
    • Jul 2007
    • 1384

    PrinterSettings in VB.NET

    Hello kind folks over here!

    I'm taking a hiatus from developing a couple of databases to work a little with VB.Net. My problem is understanding how to send page settings to the printer bypassing the Page Settings dialog box. For my application there will be no need for anyone to change paper sizes, margins, etc etc etc... so why give them too many options, eh?

    This code section is what I've been trying to use to send the paper size and layout, i.e. landscape to the printer, however it doesn't seem to do much towards making the printer listen when it talks...

    [CODE=vbnet]
    Private Sub PrintPageHandle r(ByVal sender As Object, ByVal e As Printing.PrintP ageEventArgs)
    Try

    Dim psz As New Printing.PaperS ize


    psz.PaperName = Printing.PaperK ind.A4
    e.PageSettings. PaperSize = psz
    e.PageSettings. Landscape = True

    Catch ex As Exception
    MessageBox.Show (ex.Message)[/CODE]

    Anyone able to point me in the right direction?

    Regards,
    Scott
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Have you taken a look at:
    System.Drawing. Printing.PrintD ocument
    yet? I think you need to use one of those for such things.

    Comment

    • Scott Price
      Recognized Expert Top Contributor
      • Jul 2007
      • 1384

      #3
      Well, that was fast!

      Thanks for the suggestion, but unless I'm not understanding exactly how to implement it, that doesn't work either.

      I've tried initializing a new Printing.PrintD ocument object, then setting the DefaultPageSett ings to the paper size and landscape orientation that I want, however it does the same as the first code: compiles fine, executes fine but doesn't make the printer listen when it talks :-)

      Thanks again,
      Regards,
      Scott

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Hehe, I believe THAT was the PrintDocument I ment to link.
        There used to be an article on Printing in the how-to's, but it appears to not be there anymore. Only thing that might help would be to search this forum for other's on Printing and see what they came up with?

        Comment

        • Scott Price
          Recognized Expert Top Contributor
          • Jul 2007
          • 1384

          #5
          First thing I done was search the posts here :-) No joy.

          I'll keep researching... It seems an awfully complicated way to do things, so far I've found at least three different objects that have PageSettings properties, none of which seem to be working for me. I'll post back if I ever do get it to work.

          Thanks again, and kind regards,
          Scott

          Comment

          • Scott Price
            Recognized Expert Top Contributor
            • Jul 2007
            • 1384

            #6
            Well, this is what I've found out so far: vb.net isn't exactly as easy to understand as vba :-)

            This is the sub I've gotten to work setting the landscape, margins and papersize:
            [CODE=vbnet]
            Sub Button1Click(By Val sender As Object, ByVal e As EventArgs)
            Dim prn As New Printing.PrintD ocument
            Dim pageSettings As System.Drawing. Printing.PageSe ttings = New System.Drawing. Printing.PageSe ttings

            pageSettings.La ndscape = True
            pageSettings.Pa perSize = New System.Drawing. Printing.PaperS ize("A4", 210, 297)
            pageSettings.Ma rgins.Top = 0
            pageSettings.Ma rgins.Bottom = 0
            pageSettings.Ma rgins.Left = 0
            pageSettings.Ma rgins.Right = 0

            prn.DefaultPage Settings = pageSettings
            prn.PrinterSett ings.PrinterNam e.ToString()

            AddHandler prn.PrintPage, AddressOf Me.PrintPageHan dler
            prn.Print()
            RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHan dler
            End Sub[/CODE]

            Someone else might run into this problem sometime too :-) This includes a call to the PrintPageHandle r routine, which is a custom routine that builds the rectangles, strings, etc that I'm putting onto the page.

            Thanks Plater!

            Regards,
            Scott

            Comment

            • lorenzana
              New Member
              • Feb 2008
              • 3

              #7
              Get codeforms, it will do all the printing coding for you. its free:

              http://www.neuronlabs. com/sendfile.php?fi le=nlsw0001.htm l

              Comment

              Working...