Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello!

I use PrintForm component for printing my winform.

The property myForm.FormBorderStyle is set None.

How to calculate the size of the form to make it fit on A4?


Thanks!!!
Posted
Comments
Sergey Alexandrovich Kryukov 22-Apr-14 9:08am    
Please don't re-post; this is considered as abuse. Use the page of your original question, "Improve question".
—SA

Dim Width As Integer
Dim Height As Integer

Width =Me.width
Height=Me.Height

if Width*Height==500990
MsgBox("This is A4 72 PPI")


See paper size of A4

http://www.a4papersize.org/a4-paper-size-in-pixels.php[^]
 
Share this answer
 
v2
Comments
Makso_2012 25-Apr-14 11:35am    
Thanks for the link! It will be very useful!

Can You help me to solve this problem?

I found a formula for how to calculate the size of the form. Inches multiplied by dpi screen.
I am using this formula in my solution. But when I pass the form to the PrintForm component, it does not stretch bottom. solution below.
Makso_2012 25-Apr-14 12:26pm    
Oh! I found the problem!

The height of the WinForm is not set more than 788. Maybe because it is a MDIChildren.....
VB
Dim PrintForm1 As New Microsoft.VisualBasic.PowerPacks.Printing.PrintForm()

        PrintForm1.PrintAction = System.Drawing.Printing.PrintAction.PrintToPreview

        PrintForm1.PrinterSettings.DefaultPageSettings.Margins.Left = 0
        PrintForm1.PrinterSettings.DefaultPageSettings.Margins.Top = 0
        PrintForm1.PrinterSettings.DefaultPageSettings.Margins.Right = 0
        PrintForm1.PrinterSettings.DefaultPageSettings.Margins.Bottom = 0

        Dim g As Graphics = Graphics.FromHwnd(IntPtr.Zero)

        frm.Size = New Size(CInt(21 / 2.54 * g.DpiX), CInt(29.7 / 2.54 * g.DpiY))

        PrintForm1.Print(frm, PowerPacks.Printing.PrintForm.PrintOption.ClientAreaOnly)
 
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