I cant get my price to show up in my print preview for my function.
[code]
Private Sub PrintSelected_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintSelected.PrintPage
[/code]
so far the code I have
[code]
e.Graphics.DrawString(
CStr(lblPrice.Text(lstProducts.SelectedIndex)), fntPrintFont, Brushes.Black, sngX, sngY)[/code]
isnt working I'll post the rest of my code below this to make it easier to understand maybe if somone looks at my logic they'll be able to tell me what I wrote wrong.
AlanPosted Nov 19, 2007, 4:48 AM
If you're just printing the price of the selected item here, then I'd have thought that you want to replace these lines:
For intListIndex = 0 To lstProducts.Items.Count - 1
e.Graphics.DrawString(CStr(lblPrice.Text(lstProducts.SelectedIndex)), fntPrintFont, Brushes.Black, sngX, sngY)
Next
with this one:
e.Graphics.DrawString(lblPrice.Text, fntPrintFont, Brushes.Black, sngX, sngY)
chris smithPosted Nov 18, 2007, 8:58 PM
Imports
System.IO.FileImports
System.IO'********************************************************************************************
'This button ends the form and brings you back to the main form
'********************************************************************************************
Public
Class Form1 Structure ProductRecord Dim strProduct As String Dim intQuantity As Integer Dim sngPrice As Single End Structure Dim ProRec(10) As ProductRecord Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click ' End the application Me.Close() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim intIndex As Integer Dim strFileNameIn As String TrybtnPrint.Enabled =
False Dim Reader As New IO.StreamReader("C:\products.txt")strFileNameIn =
"products.txt"intIndex = 0
Do Until Reader.Peek = -1 With ReaderProRec(intIndex).strProduct = .ReadLine()
ProRec(intIndex).intQuantity =
CInt(.ReadLine())ProRec(intIndex).sngPrice =
CSng(.ReadLine())lstProducts.Items.Add(ProRec(intIndex).strProduct)
End WithintIndex += 1
LooplstProducts.SelectedIndex = 0
Reader.Close()
Catch ex As ExceptionMessageBox.Show(ex.Message,
"Error in Reading file", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) End Try End Sub Private Sub lstProducts_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstProducts.SelectedIndexChangedlblPrice.Text = (
"$") & CStr((ProRec(lstProducts.SelectedIndex).sngPrice)) End Sub Private Sub btnOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOrder.Click Dim outputfile As StreamWriteroutputfile = AppendText(
"C:\outputfile.txt")lblItems.Text = ProRec(lstProducts.SelectedIndex).strProduct
lblCost.Text = (
"$") & CStr(CSng(lblPrice.Text) * nudQuantity.Value)outputfile.WriteLine(lblItems.Text)
outputfile.WriteLine(lblCost.Text)
outputfile.Close()
btnOrder.Enabled =
FalsebtnPrint.Enabled =
TruelstProducts.Enabled =
FalsenudQuantity.Enabled =
False End Sub Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.ClickPrintPreviewSelected.Document = PrintSelected
PrintPreviewSelected.PrintPreviewControl.Zoom = 1
PrintPreviewSelected.ShowDialog()
btnOrder.Enabled =
TruebtnPrint.Enabled =
FalselstProducts.Enabled =
TruenudQuantity.Enabled =
True End Sub Private Sub btnReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReport.ClickPrintPreviewProducts.Document = PrintReport
PrintPreviewProducts.PrintPreviewControl.Zoom = 1
PrintPreviewProducts.ShowDialog()
End Sub Private Sub PrintReport_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintReport.PrintPage Dim sngX As Single Dim sngY As Single Dim fntPrintFont As New Font("Arial", 12) Dim sngLineHeight As Single = fntPrintFont.GetHeight + 2 Dim intListIndex As IntegerbtnPrint.Enabled =
TruesngX = e.MarginBounds.Left
sngY = e.MarginBounds.Top
'print headinge.Graphics.DrawString(
" Iventory Report", fntPrintFont, Brushes.Black, sngX, sngY)sngY += sngLineHeight
sngY += sngLineHeight
e.Graphics.DrawString(
"Products Quantity Price", fntPrintFont, Brushes.Black, sngX, sngY)sngY += sngLineHeight
sngY += sngLineHeight
'display list of Products For intListIndex = 0 To lstProducts.Items.Count - 1e.Graphics.DrawString(
CStr(lstProducts.Items(intListIndex)), fntPrintFont, Brushes.Black, sngX, sngY)sngY += sngLineHeight
NextsngY += sngLineHeight
sngY += sngLineHeight
End Sub Private Sub PrintSelected_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintSelected.PrintPage Dim sngX As Single Dim sngY As Single Dim fntPrintFont As New Font("Arial", 12) Dim sngLineHeight As Single = fntPrintFont.GetHeight + 2 Dim intListIndex As IntegersngX = e.MarginBounds.Left
sngY = e.MarginBounds.Top
'print headinge.Graphics.DrawString(
" Order", fntPrintFont, Brushes.Black, sngX, sngY)sngY += sngLineHeight
sngY += sngLineHeight
e.Graphics.DrawString(
"Products Cost", fntPrintFont, Brushes.Black, sngX, sngY)sngY += sngLineHeight
e.Graphics.DrawString(
"-----------------------", fntPrintFont, Brushes.Black, sngX, sngY)sngY += sngLineHeight
sngY += sngLineHeight
'display list of Productse.Graphics.DrawString(
CStr(lstProducts.Items(lstProducts.SelectedIndex)), fntPrintFont, Brushes.Black, sngX, sngY)sngY += sngLineHeight
sngY += sngLineHeight
For intListIndex = 0 To lstProducts.Items.Count - 1e.Graphics.DrawString(
CStr(lblPrice.Text(lstProducts.SelectedIndex)), fntPrintFont, Brushes.Black, sngX, sngY) NextsngY += sngLineHeight
sngY += sngLineHeight
End SubEnd
Class