How do I Remove the margins from PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.ClientAreaOnly)

Locked How do I Remove the margins from PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.ClientAreaOnly)

  • lunedì 10 marzo 2008 23:37
     
     

    I am using PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.ClientAreaOnly). Im trying to print out a 4 inch by 6 inch label. I have designed a form just like the label I want to print at the same size. When I print it I get only a portion on the label. If I use a 8.5 by 11 paper it prints the correct label on the paper, except it prints out with a top margin of about 1.5 inches and a left side margin of about 1.5 inches.. Here is the code That I''m Using.

     

    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None

    If test1 = "Print Preview" Then

    PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview

    Else

    PrintForm1.PrintAction = Printing.PrintAction.PrintToPrinter

    End If

    PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.ClientAreaOnly)

    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Fixed3D

     

     The test1 is just a way of test printing without wasting ink or paper. Which Ive Wasted too much trying to get it to work.

    I need to adjust the print so that the top, left corner of the form is at the top, left corner of the lable. I can adjust the printer driver preferences up about .25 inches. I have no left adjustment in preferences. The label printer that im using is a zebra stripe S600.

     

    Curtis

     

Tutte le risposte

  • lunedì 10 marzo 2008 23:57
     
     Con risposta

    here are some examples to change the margins

    you have to play with them individually to see how it works, it is a little awkward sometimes

     

    Me.PrintForm1.PrinterSettings.DefaultPageSettings.Landscape = True

    Me.PrintForm1.PrinterSettings.DefaultPageSettings.Margins.Top = 60

    Me.PrintForm1.PrinterSettings.DefaultPageSettings.Margins.Left = 50

    Me.PrintForm1.PrinterSettings.DefaultPageSettings.Margins.Right = 0 '0.5

    Me.PrintForm1.PrinterSettings.DefaultPageSettings.Margins.Bottom = 0 '0.5

     

  • martedì 11 marzo 2008 00:28
     
     

    Thank You I searched all weekend for the info you just gave me and it solve my problem completely.

     

    curtis

     

  • sabato 17 maggio 2008 17:04
     
     
    Jeff,

    Just want to say Thanks for this information.  Searched through the Help and got some info, but this is exactly what I needed.  I appreciate you answering questions in this forum!

    Keith
  • sabato 17 maggio 2008 19:05
     
     

    You are both welcome.

     

    Just some info for you.  I do search the web and the documentation for help but i find many times it does me just as well to play with the methods and properties using intellisense.  I go through them quite a bit as i play with code.  I have had better luck with this than searching other places most of the time.  Part of the reason is that when i first started learning i did not have the internet.  So for months i used the help documentation and just playing with intellisense.  Anyway, that is nothing new to anyone but it will help if you just take the object you are trying to use and let intellisense bring up everything for you.  I found the printer settings in a few minutes of playing with intellisense.

     

    Glad i could help

    Jeff

  • martedì 8 marzo 2011 06:23
     
     

    Thank You!!!!

     

    This Really Helped me Too!!!!

     

     

  • domenica 15 aprile 2012 23:14
     
     

    I appreciated that your code.
    Did you can configure it to create a form in A4 size?
    In this sense, cover the red lines that form, taking maximum advantage of the A4 sheet?

  • martedì 17 aprile 2012 23:33
     
     
    Grateful friend.

    Only one small problem.

    If you turn the page:

    Me.PrintForm1.PrinterSettings.DefaultPageSettings.Landscape = False

    Cut down printing.

    I would not cut it.

    Can you help me?
  • sabato 21 aprile 2012 00:24
     
     Risposta suggerita Contiene codice
    Imports System.Drawing.Printing
    Public Class Form1
        Private WithEvents pd As New PrintDocument
        Private WithEvents Button1 As New Button With {.Location = New Point(50, 50), .Text = "print", .Parent = Me}
    
        Private bmp As Bitmap
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            bmp = New Bitmap(Panel1.ClientSize.Width, Panel1.ClientSize.Height)
            Panel1.DrawToBitmap(bmp, Panel1.ClientRectangle)
    
            pd.Print()
    
        End Sub
        Private Sub pd_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pd.PrintPage
    
            Dim area = e.PageSettings.PrintableArea
            Dim ar1 = area.Width / area.Height
            Dim ar2 = CSng(bmp.Width / bmp.Height)
    
            If ar1 > ar2 Then
                Dim NewWidth = bmp.Width * area.Height / bmp.Height
                Dim x = (area.Width - NewWidth) / 2
                e.Graphics.DrawImage(bmp, x, area.Top, NewWidth, area.Height)
            Else
                Dim NewHeight = bmp.Height * area.Width / bmp.Width
                Dim y = (area.Height - NewHeight) / 2
                e.Graphics.DrawImage(bmp, area.Left, y, area.Width, NewHeight)
            End If
    
            e.HasMorePages = False
    
        End Sub
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Using g = Graphics.FromHwnd(IntPtr.Zero)
                Panel1.Size = New Size(CInt(21 / 2.54 * g.DpiX), CInt(29.7 / 2.54 * g.DpiY))
            End Using
          End Sub
    End Class