I have this code from the internet but it didn't work well.

I want to set the margin of the Report Viewer during runtime. Because I have this form to fill up. Instead of handwriting it. I programmed it. But there are certain positions of the textboxes in which it should appear.

My big problem is that how could I set the margin of the Report Viewer to 0?

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim instance As New PageSettings()
Dim value As New Margins(0, 0, 0, 0)

instance.Margins = value


I've never used ReportViewer, but I found this post:

set page layout for report viewer...

The following is converted and and adapted for VB .NET:

Dim myPageSettings As New System.Drawing.Printing.PageSettings()

myPageSettings.Margins =  New System.Drawing.Printing.Margins(0, 0, 0, 0)

Dim paperSize As System.Drawing.Printing.PaperSize = New System.Drawing.Printing.PaperSize()

'ToDo: update with the PaperKind 
'that your printer uses
paperSize.RawKind = System.Drawing.Printing.PaperKind.Letter

'paperSize.RawKind = System.Drawing.Printing.PaperKind.A4

myPageSettings.PaperSize = paperSize

'False for "Portrait"
'True for "Landscape"
myPageSettings.Landscape = False



However, it's untested, so not sure if it works or not.

Edited 2 Years Ago by cgeier

Your page margins are subject to the limitations of your printer. Check what the minimum margins are for your printer. Also ensure you've specified the correct paper size.

This question has already been answered. Start a new discussion instead.