| | |
Printing HELP
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2007
Posts: 7
Reputation:
Solved Threads: 0
I want the print button below to print out whatever the user orders and not the entire order list. The List is steam read into the list box I made. My problem is when I click the print button it displays all the products in the print preview instead of the item ordered. I tried selected item for the print button thinking it would only show the selected item in the print preview with no luck could I get some help please?
VB.NET Syntax (Toggle Plain Text)
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 Try btnPrint.Enabled = False Dim Reader As New IO.StreamReader("products.txt") strFileNameIn = "products.txt" intIndex = 0 Do Until Reader.Peek = -1 With Reader ProRec(intIndex).strProduct = .ReadLine() ProRec(intIndex).intQuantity = CInt(.ReadLine()) ProRec(intIndex).sngPrice = CSng(.ReadLine()) lstProducts.Items.Add(ProRec(intIndex).strProduct) End With intIndex += 1 Loop lstProducts.SelectedIndex = 0 Reader.Close() Catch ex As Exception MessageBox.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.SelectedIndexChanged lblPrice.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 StreamWriter 'If lstProducts.SelectedIndex = -1 Then 'MsgBox("Select a prouduct", MsgBoxStyle.Critical) ' Else ' Select Case CStr(lstProducts.SelectedIndex) ' Case CStr(0) = nudQuantity.Value = 5 ' MsgBox("Select a prouduct", MsgBoxStyle.Critical) ' Case CStr(1) ' MsgBox("Select a prouduct", MsgBoxStyle.Critical) ' Case CStr(2) ' MsgBox("Select a prouduct", MsgBoxStyle.Critical) ' End Select 'End If outputfile = 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 = False btnPrint.Enabled = True End Sub Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click PrintPreviewSelected.Document = PrintSelected PrintPreviewSelected.PrintPreviewControl.Zoom = 1 PrintPreviewSelected.ShowDialog() End Sub Private Sub PrintPreviewDialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreviewProducts.Load End Sub Private Sub btnReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReport.Click PrintPreviewProducts.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 Integer sngX = e.MarginBounds.Left sngY = e.MarginBounds.Top 'print heading e.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 - 1 e.Graphics.DrawString(CStr(lstProducts.Items(intListIndex)), fntPrintFont, Brushes.Black, sngX, sngY) sngY += sngLineHeight Next sngY += 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 Integer sngX = e.MarginBounds.Left sngY = e.MarginBounds.Top 'print heading e.Graphics.DrawString("Order", fntPrintFont, Brushes.Black, sngX, sngY) sngY += sngLineHeight sngY += sngLineHeight e.Graphics.DrawString("Products Cost", fntPrintFont, Brushes.Black, sngX, sngY) sngY += sngLineHeight sngY += sngLineHeight 'display list of Products For intListIndex = 0 To lstProducts.Items.Count - 1 e.Graphics.DrawString(CStr(lstProducts.Items(intListIndex)), fntPrintFont, Brushes.Black, sngX, sngY) sngY += sngLineHeight Next sngY += sngLineHeight sngY += sngLineHeight End Sub End Class
•
•
Join Date: Nov 2007
Posts: 7
Reputation:
Solved Threads: 0
I'm working on this project for class I steam read theses products into a list box on my form I made in VB2005. I'm having an issue when I go to print tho. My first problem is that I have a list box a print button and a report button and also and exit button. When the User Orders one of my products I made it so the print button is enabled and prints out the product selected so far tho instead of printing out just what the user selected it prints out all the products. Could you please look at me code and tell me If I'm doing this right I'll post the whole thing but again the print statement is the only thing I need an answer to if somone would please look at it thanks. Again I'm just posting the whole code so you can see my logic the line in Print Selected is the problem I said print selected item and it gave me an error thanks alot again.
•
•
Join Date: Nov 2007
Posts: 7
Reputation:
Solved Threads: 0
VB.NET Syntax (Toggle Plain Text)
e.Graphics.DrawString(CStr(lstProducts.Items(intListIndex.SelectedIndex)), fntPrintFont, Brushes.Black, sngX, sngY)sngY += sngLineHeight
This line right here seeems to be giving me the most trouble I put selectedIndex in so that when I click print it would only show the product selected. But VB keeps giving me an error message saying.
'Selected index' is not a member of integer'
•
•
•
•
Dim intListIndex As Integer
intListIndex.SelectedIndex
to print only what the user select try this
VB.NET Syntax (Toggle Plain Text)
e.Graphics.DrawString(lstProducts.SelectedItem, fntPrintFont, Brushes.Black, sngX, sngY)
Last edited by manal; Nov 18th, 2007 at 5:52 am.
"give only what u willing to receive "
•
•
Join Date: Nov 2007
Posts: 7
Reputation:
Solved Threads: 0
Well that Works with the products but I want the price too the price is declared up above and is read with the code.
Dim sngPrice As Single
I tried this to print out the price
it didnt work
Dim sngPrice As Single
I tried this to print out the price
VB.NET Syntax (Toggle Plain Text)
e.Graphics.DrawString(CStr(lblCost.Text(lstProducts.SelectedIndex)), fntPrintFont, Brushes.Black, sngX, sngY)
![]() |
Similar Threads
- edges of print missing when printing web pages (Web Browsers)
- Windows 2000 Adv Server and "Printing Subsystem" (Windows NT / 2000 / XP)
- Problem printing from IE6 (Web Browsers)
- Mac10.3 Printing Problems (OS X)
- WinXP, RH9, Samba, and Printing (*nix Software)
- Printing pictures (Windows NT / 2000 / XP)
- Linux printing questions (*nix Hardware Configuration)
Other Threads in the VB.NET Forum
- Previous Thread: Saving rtf file to database
- Next Thread: Batch Files in Compact Framework
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net .net2008 2005 2008 access account application array arrays basic beginner browser button buttons center checkbox client code convert cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic eclipse excel fade filter forms ftp generatetags gridview html images inline input insert intel internet lib listview mobile monitor net objects open panel passingparameters pdf picturebox port position print printing problem read remove save searchvb.net select serial settings shutdown soap sorting sqlserver survey table temperature textbox timer timespan transparency trim update user validation vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web webbrowser winforms wpf wrapingcode year





