Click here to Skip to main content
15,898,987 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: How to create a relational query? Pin
Dave Kreskowiak13-Mar-10 2:20
mveDave Kreskowiak13-Mar-10 2:20 
Questionprinter from file [modified] ... resolved Pin
Daniel Engelkes11-Mar-10 14:41
Daniel Engelkes11-Mar-10 14:41 
AnswerRe: printer from file Pin
Luc Pattyn11-Mar-10 15:01
sitebuilderLuc Pattyn11-Mar-10 15:01 
AnswerRe: printer from file [modified] Pin
Andy_L_J11-Mar-10 18:11
Andy_L_J11-Mar-10 18:11 
AnswerRe: printer from file Pin
The Man from U.N.C.L.E.12-Mar-10 8:35
The Man from U.N.C.L.E.12-Mar-10 8:35 
GeneralRe: printer from file Pin
Daniel Engelkes12-Mar-10 14:54
Daniel Engelkes12-Mar-10 14:54 
GeneralRe: printer from file Pin
Luc Pattyn12-Mar-10 15:50
sitebuilderLuc Pattyn12-Mar-10 15:50 
GeneralRe: printer from file Pin
Wayne Gaylard12-Mar-10 17:00
professionalWayne Gaylard12-Mar-10 17:00 
This is how I do my report printing. I have adapted one of my reports to sort of get what you are looking for. I used a set of arrays to input the data, whereas you would obviously get it from the app.

VB.NET
Private items() As String = {"Cheeseburger", "Onion Rings", "Chicken Sandwich", "Milk Shake"}
Private costs() As Integer = {5, 6, 5, 2}
Private quantities() As Integer = {1, 2, 2, 2}
Private intLinesPerPage As Integer = 25
Private intLinesPrinted As Integer

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

    PrintHeadings(e)
    PrintDetails(e)

End Sub

Private Sub PrintHeadings(ByVal e As System.Drawing.Printing.PrintPageEventArgs)

    Dim recMenu As New System.Drawing.Rectangle(40, 20, 100, 40)
    Dim recQuantity As New System.Drawing.Rectangle(120, 20, 60, 40)
    Dim recCost As New System.Drawing.Rectangle(180, 20, 60, 40)
    Dim recTotal As New System.Drawing.Rectangle(260, 20, 80, 40)
    Dim fntDefault As New System.Drawing.Font("Arial", 8, FontStyle.Underline)
    Dim fmtCentre As New StringFormat
    fmtCentre.Alignment = StringAlignment.Center
    e.Graphics.DrawString("Menu Items", fntDefault, Brushes.Black, recMenu, fmtCentre)
    e.Graphics.DrawString("Quantity", fntDefault, Brushes.Black, recQuantity, fmtCentre)
    e.Graphics.DrawString("Cost Price", fntDefault, Brushes.Black, recCost, fmtCentre)
    e.Graphics.DrawString("Total", fntDefault, Brushes.Black, recTotal, fmtCentre)

End Sub

Private Sub PrintDetails(ByVal e As System.Drawing.Printing.PrintPageEventArgs)

    Dim strMenu As New StringBuilder("")
    Dim strQuantity As New StringBuilder("")
    Dim strCost As New StringBuilder("")
    Dim strTotal As New StringBuilder("")
    Dim recMenu As New System.Drawing.Rectangle(20, 80, 100, 600)
    Dim recQuantity As New System.Drawing.Rectangle(120, 80, 60, 600)
    Dim recCost As New System.Drawing.Rectangle(180, 80, 60, 600)
    Dim recTotal As New System.Drawing.Rectangle(240, 80, 80, 600)
    Dim intLastLine As Integer = intLinesPrinted + intLinesPerPage
    If intLastLine >= items.Length - 1 Then
        intLastLine = items.Length - 1
        e.HasMorePages = False
    Else
        e.HasMorePages = True
    End If
    Dim i As Integer
    For i = intLinesPrinted To intLastLine
        Dim strMenuItem As String = items(i)
        If Len(strMenuItem) > 30 Then
            strMenuItem = Microsoft.VisualBasic.Left(strMenuItem, 27) & "..."
        End If
        strMenu.Append(strMenuItem & ControlChars.NewLine)
        strQuantity.Append(quantities(i) & ControlChars.NewLine)
        strCost.Append(Format(costs(i), "0.00") & ControlChars.NewLine)
        strTotal.Append(Format(quantities(i) * costs(i), "0.00") & ControlChars.NewLine)
    Next
    intLinesPrinted = i
    Dim fntDefault As New System.Drawing.Font("Arial", 7)
    Dim fmtCentre As New StringFormat
    fmtCentre.Alignment = StringAlignment.Center
    Dim fmtLeft As New StringFormat
    fmtLeft.Alignment = StringAlignment.Near
    Dim fmtRight As New StringFormat
    fmtRight.Alignment = StringAlignment.Far
    e.Graphics.DrawString(strMenu.ToString, fntDefault, Brushes.Black, recMenu, fmtRight)
    e.Graphics.DrawString(strQuantity.ToString, fntDefault, Brushes.Black, recQuantity, fmtCentre)
    e.Graphics.DrawString(strCost.ToString, fntDefault, Brushes.Black, recCost, fmtRight)
    e.Graphics.DrawString(strTotal.ToString, fntDefault, Brushes.Black, recTotal, fmtRight)

End Sub

Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click

    If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
        PrintDocument1.Print()
    End If

End Sub


You would need to play around with this a bit, but should get where you want to go with it. Hope this helps.
GeneralRe: printer from file Pin
Luc Pattyn12-Mar-10 18:43
sitebuilderLuc Pattyn12-Mar-10 18:43 
QuestionCode Question Pin
derekzundl11-Mar-10 8:20
derekzundl11-Mar-10 8:20 
AnswerRe: Code Question Pin
Smithers-Jones11-Mar-10 9:33
Smithers-Jones11-Mar-10 9:33 
Questionwriting to text file [modified] ... resolved Pin
Daniel Engelkes11-Mar-10 7:39
Daniel Engelkes11-Mar-10 7:39 
AnswerRe: writing to text file Pin
David Mujica11-Mar-10 7:45
David Mujica11-Mar-10 7:45 
AnswerRe: writing to text file Pin
Dave Kreskowiak11-Mar-10 9:08
mveDave Kreskowiak11-Mar-10 9:08 
Questioncodin prblm Pin
gcina11-Mar-10 2:35
gcina11-Mar-10 2:35 
RantRe: codin prblm Pin
Smithers-Jones11-Mar-10 3:00
Smithers-Jones11-Mar-10 3:00 
AnswerRe: codin prblm Pin
JHizzle11-Mar-10 3:11
JHizzle11-Mar-10 3:11 
GeneralRe: codin prblm Pin
εїзεїзεїз11-Mar-10 4:50
εїзεїзεїз11-Mar-10 4:50 
GeneralRe: codin prblm Pin
Dave Kreskowiak11-Mar-10 5:02
mveDave Kreskowiak11-Mar-10 5:02 
GeneralRe: codin prblm Pin
εїзεїзεїз11-Mar-10 5:16
εїзεїзεїз11-Mar-10 5:16 
GeneralRe: codin prblm Pin
Smithers-Jones11-Mar-10 5:17
Smithers-Jones11-Mar-10 5:17 
GeneralRe: codin prblm Pin
εїзεїзεїз11-Mar-10 5:44
εїзεїзεїз11-Mar-10 5:44 
GeneralRe: codin prblm Pin
Smithers-Jones11-Mar-10 6:04
Smithers-Jones11-Mar-10 6:04 
GeneralRe: codin prblm Pin
εїзεїзεїз11-Mar-10 6:06
εїзεїзεїз11-Mar-10 6:06 
GeneralTag Line Pin
The Man from U.N.C.L.E.11-Mar-10 7:55
The Man from U.N.C.L.E.11-Mar-10 7:55 

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.