PrintForm - how to adjust margins?

I use PrintForm component and I want to adjust margins of the print page.
I have tried this:

Dim margins As New Printing.Margins(100, 100, 100, 100)
PrintForm1.PrinterSettings.DefaultPageSettings.Margins = margins
PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.ClientAreaOnly)

but it does't work.

[332 byte] By [RankoNS] at [2008-2-15]
# 1

Unfortunately, I believe this is a bug. The PrintForm component does not honor the margins and always prints the image of the form at 0,0 as the VB6 Form.Print method did

JohnHart_MSFT at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...
# 2
As a newcomer to the Power Packs, I don't know how things progress! Is this problem likely to be fixed, or should we log requests somewhere? I suppose it will take forever, whichever the answer, and I'd better code up my own solution (a shame, since this does almost everything I need).
StroudPete at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...
# 3

Hi Pete,

Again I appolige you have run into this problem. The PrintForm component was originaly designed to duplicate that of the original VB6 Form.Print functionality which printed the form at the top left of the page. We will consider fixing this but at this time I can not tell you exactly when it will happen.

If you find bugs with any Power Pack you can feel free to post them here or submit a bug at

https://connect.microsoft.com/feedback/default.aspx?SiteID=210&wa=wsignin1.0

If you do feel that you need to provide your own solution you might take a look at using the DrawToBitmap. This may not work for all forms, especially if you have an ActiveX control on the form but for some forms it will work. The easiest way to do this is add a Panel to form and add all controls to is. Then simply use a DrawToBitmap to create a bitmap of the form and draw the image on the printdocument where ever you would like.

For Example:

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

Dim b As New Bitmap(Panel1.ClientSize.Width, Panel1.ClientSize.Height)

Panel1.DrawToBitmap(b, Panel1.ClientRectangle)

e.Graphics.DrawImage(b, New Point(100, 100))

End Sub

I hope that helps.

JohnHart_MSFT at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...
# 4

Hi this was extreemly helpful, i was searching for an alternitive to the printform control as my college would not install the powerpack.

I wanted to print the part of an invoice form as part of my coursework, this allowed me to print the invoice without getting the print button on the print out.

Thank you very much this was extreemly helpful.

wiccan2 at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...
# 5
I'm revisiting this. I put up with the lack of margin control for basic screen dumps, but now I'm doing other printing I want a consistent setup/preview/print scenario, which means handling margins. So, thanks for the pointer John. I'm ditching the powerpack, as my screens don't involve scrolling and therefore the powerpack doesn't really offer anything.

For anyone who's wants to try John's approach, I'll add a little. If you want to print the entire form including borders, this code will do it:

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim b As New Bitmap(Me.Width, Me.Height)
Dim rect As New Rectangle(New Point(0, 0), Me.Size)
Me.DrawToBitmap(b, rect)
e.Graphics.DrawImage(b, New Point(0, 0))
End Sub

Note the DrawImage at 0,0 does print in the top left corner, like the Powerpack! John had it printing at 100,100. You could control margins with this, but it isn't the way to do it!

If you're a complete beginner, note all you need to do to add this printing capability is to drag and drop a PrintDocument control onto the form, add a control to initiate printing (I've used a button in my quick test) and in your code create a handler for the button:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintDocument1.Print()
End Sub

Obviously there is more needed to provide margin control, printer choice, etc, but this isn't a tutorial on printing!

I hope that helps someone!

Pete Jones

StroudPete at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...