Click here to Skip to main content
16,005,038 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionPublishing in the 2.0 framework Pin
KreativeKai11-Jan-07 8:20
professionalKreativeKai11-Jan-07 8:20 
QuestionHELP WITH PRINTING MARGINS PLS READ! Pin
vbbeg11-Jan-07 6:38
vbbeg11-Jan-07 6:38 
AnswerRe: HELP WITH PRINTING MARGINS PLS READ! Pin
Duncan Edwards Jones12-Jan-07 3:11
professionalDuncan Edwards Jones12-Jan-07 3:11 
GeneralRe: HELP WITH PRINTING MARGINS PLS READ! Pin
vbbeg12-Jan-07 5:11
vbbeg12-Jan-07 5:11 
GeneralRe: HELP WITH PRINTING MARGINS PLS READ! Pin
Dave Kreskowiak12-Jan-07 6:28
mveDave Kreskowiak12-Jan-07 6:28 
GeneralRe: HELP WITH PRINTING MARGINS PLS READ! Pin
vbbeg12-Jan-07 6:44
vbbeg12-Jan-07 6:44 
GeneralRe: HELP WITH PRINTING MARGINS PLS READ! Pin
Dave Kreskowiak12-Jan-07 12:15
mveDave Kreskowiak12-Jan-07 12:15 
GeneralRe: HELP WITH PRINTING MARGINS PLS READ! Pin
vbbeg13-Jan-07 6:12
vbbeg13-Jan-07 6:12 
Hi Dave

Here is my code as you requested . Just to remind you print preview margins are great but printouts are not but only slightly off. i look forward to your comments to hopefully include some things to do.

CODE
====

RE: Imports System.Drawing.Printing
Public Class supreport

Private m_PagesPrinted As Integer
Private totalpages As Integer



' Display a print preview.
Private Sub btnPrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintPreview.Click


' Make a PrintDocument and attach it to
' the PrintPreview dialog.
dlgPrintPreview.Document = PreparePrintDocument()

dlgPrintPreview.WindowState = FormWindowState.Maximized
dlgPrintPreview.PrintPreviewControl.Zoom = 1.0 'set zoom preview to %100

' Preview.
dlgPrintPreview.WindowState = FormWindowState.Maximized
dlgPrintPreview.ShowDialog()



End Sub



Private Function PreparePrintDocument() As PrintDocument
' Make the PrintDocument object.

Dim print_document As New PrintDocument
With PageSetupDialog1
.PageSettings = print_document.DefaultPageSettings

End With

If PageSetupDialog1.ShowDialog = Windows.Forms.DialogResult.Yes Then
print_document.DefaultPageSettings = PageSetupDialog1.PageSettings
End If




AddHandler print_document.BeginPrint, AddressOf Print_BeginPrint
AddHandler print_document.QueryPageSettings, AddressOf Print_QueryPageSettings
AddHandler print_document.PrintPage, AddressOf Print_PrintPage
AddHandler print_document.EndPrint, AddressOf Print_EndPrint

' Return the object.
Return print_document
End Function


' Get ready to print pages.
Private Sub Print_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs)

m_PagesPrinted = 0
getdata() 'load data to print/preview


End Sub



' Print the next page.
Private Sub Print_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)


' Increment the page number.
m_PagesPrinted += 1



'**********RECTANGLES
Dim headingrect As New Rectangle(130, 100, 600, 800)

Dim DateRect As New Rectangle(e.MarginBounds.Left, 170, 100, 800)
Dim InvRect As New Rectangle(e.MarginBounds.Left + 130, 170, 130, 800)
Dim NameRect As New Rectangle(e.MarginBounds.Left + 281, 170, 100, 800)
Dim PDRect As New Rectangle(390, 170, 100, 800)
'*****************
'********FONTS
Dim headingfont As Font
headingfont = New Font("Times New Roman", 12, FontStyle.Underline, GraphicsUnit.Point)
Dim datafont As Font
datafont = New Font("Times New Roman", 10, FontStyle.Regular, GraphicsUnit.Point)
Dim subheadingsfont As Font
subheadingsfont = New Font("Time New Roman", 10, FontStyle.Regular, GraphicsUnit.Point)

'**************
'********STRING FORMATS
Dim headingstringformat As New StringFormat
headingstringformat.Alignment = StringAlignment.Center

Dim datastringformat As New StringFormat
datastringformat.Alignment = StringAlignment.Near
'********************

Dim reportheading As String = "Supplier Report As Of " & Today
Dim companyheading As String = "Company"
Dim addressheading As String = "Address"
Dim suburbheading As String = "Suburb"
Dim pcodeheading As String = "Postcode"
Dim ph1heading As String = "Phone 1"
Dim ph2heading As String = "Phone 2"
Dim contactheading As String = "Contact"

e.Graphics.DrawString(reportheading, headingfont, _
Brushes.Black, headingrect, headingstringformat) ' draw company heading details

e.Graphics.DrawString(ComData, datafont, Brushes.Black, DateRect, datastringformat)
e.Graphics.DrawString(AddressData, datafont, Brushes.Black, InvRect, datastringformat)
e.Graphics.DrawString(SubData, datafont, Brushes.Black, NameRect, datastringformat)
e.Graphics.DrawString(PcodeData, datafont, Brushes.Black, PDRect, datastringformat)


e.Graphics.DrawString(companyheading, subheadingsfont, Brushes.Black, e.MarginBounds.Left, 150)
e.Graphics.DrawString(addressheading, subheadingsfont, Brushes.Black, e.MarginBounds.Left + 130, 150)
e.Graphics.DrawString(suburbheading, subheadingsfont, Brushes.Black, 320, 150)
e.Graphics.DrawString(pcodeheading, subheadingsfont, Brushes.Black, 390, 150)
e.Graphics.DrawString(ph1heading, subheadingsfont, Brushes.Black, 480, 150)
e.Graphics.DrawString(ph2heading, subheadingsfont, Brushes.Black, 560, 150)
e.Graphics.DrawString(contactheading, subheadingsfont, Brushes.Black, 660, 150)



' Draw the margins (for debugging).

e.Graphics.DrawRectangle(Pens.SkyBlue, e.MarginBounds)


Dim the_font As Font

Dim string_format As New StringFormat
the_font = New Font("Times New Roman", _
8, FontStyle.Regular, GraphicsUnit.Point)



Dim getwidth As Int32 = e.PageBounds.Width
Dim getbottom As Int32 = e.MarginBounds.Bottom

getwidth = getwidth / 2
' MsgBox("getwidth " & getwidth)

e.Graphics.DrawString("( Page " & m_PagesPrinted.ToString & ")", _
the_font, Brushes.Black, getwidth, _
(120), _
string_format)

End Sub



End Class
GeneralRe: HELP WITH PRINTING MARGINS PLS READ! Pin
Dave Kreskowiak15-Jan-07 5:36
mveDave Kreskowiak15-Jan-07 5:36 
GeneralRe: HELP WITH PRINTING MARGINS PLS READ! Pin
vbbeg16-Jan-07 3:24
vbbeg16-Jan-07 3:24 
QuestionAnyone know any good resources on developing right-click/context menus for form controls??? Pin
Joey Picerno11-Jan-07 5:41
Joey Picerno11-Jan-07 5:41 
AnswerRe: Anyone know any good resources on developing right-click/context menus for form controls??? Pin
Kschuler11-Jan-07 9:07
Kschuler11-Jan-07 9:07 
QuestionAnother question about Graphics.DrawString Pin
Savas Cilve11-Jan-07 4:10
Savas Cilve11-Jan-07 4:10 
AnswerRe: Another question about Graphics.DrawString Pin
Dave Kreskowiak11-Jan-07 4:15
mveDave Kreskowiak11-Jan-07 4:15 
GeneralRe: Another question about Graphics.DrawString Pin
Savas Cilve11-Jan-07 4:23
Savas Cilve11-Jan-07 4:23 
GeneralRe: Another question about Graphics.DrawString Pin
Dave Kreskowiak11-Jan-07 5:37
mveDave Kreskowiak11-Jan-07 5:37 
GeneralRe: Another question about Graphics.DrawString Pin
Savas Cilve11-Jan-07 6:08
Savas Cilve11-Jan-07 6:08 
QuestionInsert File Pin
jds120711-Jan-07 3:56
jds120711-Jan-07 3:56 
QuestionWhat??? Pin
CPallini11-Jan-07 4:06
mveCPallini11-Jan-07 4:06 
AnswerRe: Insert File Pin
Dave Kreskowiak11-Jan-07 4:12
mveDave Kreskowiak11-Jan-07 4:12 
GeneralRe: Insert File Pin
Colin Angus Mackay11-Jan-07 4:51
Colin Angus Mackay11-Jan-07 4:51 
GeneralRe: Insert File Pin
Dave Kreskowiak11-Jan-07 4:56
mveDave Kreskowiak11-Jan-07 4:56 
GeneralRe: Insert File Pin
jds120711-Jan-07 6:01
jds120711-Jan-07 6:01 
GeneralRe: Insert File Pin
Dave Kreskowiak11-Jan-07 6:52
mveDave Kreskowiak11-Jan-07 6:52 
GeneralRe: Insert File Pin
jds120711-Jan-07 7:25
jds120711-Jan-07 7:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.