lothos12345 Posted March 6, 2004 Posted March 6, 2004 Is there a way in VB.NET to printout every item in a listbox? Quote
yewmeng Posted March 6, 2004 Posted March 6, 2004 Is there a way in VB.NET to printout every item in a listbox? try this dim listBoxItem as string ' item in listbox for each listBoxItem in listbox1.items messagebox.show(listBoxItem) next Quote
*Experts* DiverDan Posted March 6, 2004 *Experts* Posted March 6, 2004 If you already know how to write a print handler then this should be easy. Dim ListBoxItems as string Dim i as Integer For i = 0 to ListBox1.Items.Count - 1 ListBoxItems &= ListBox1.Items(i) & vbCrLf Next That will setup the list box items vertically for printing. A simple print handler will take care of the rest. btw: how do you get the equivalent of the old tags? Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
lothos12345 Posted March 6, 2004 Author Posted March 6, 2004 Printhandler Unforunately I am not quite clear how to write a printhandler. Any examples would be greatly appreciated. Quote
*Experts* DiverDan Posted March 7, 2004 *Experts* Posted March 7, 2004 Rather than post a simple print handler here, try a Google search or better yet MSDN, there you'll exactly what you are looking for in a download...I think its called Simple Printing... Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
kas Posted March 7, 2004 Posted March 7, 2004 Hi Lothos, Here's one basic way of tackling this: 1. Add a PrintDocument component to your form. (Available from the toolbox). It will appear in the Component Tray below the form. 2. Leave it at the default name of PrintDocument1. 3. Add this Declaration to the top of the form's code: Dim strPrint As String = "" 4. Add this procedure to the form's code: Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage e.Graphics.DrawString(strPrint, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 50, 50) End Sub 5. Change any settings of fonts, colors, etc to your choice. 6. Put this code in the click event of the button you use to start the print process. (It doesn't have to be a button but it's usual) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer For i = 0 To ListBox1.Items.Count - 1 strPrint &= ListBox1.Items(i) & vbCrLf Next PrintDocument1.Print() End Sub 7. Make sure your listbox's name is correct in the code above (example is ListBox1). 8. Run the project. Your printer will print the list of items from the listbox. Hope this helps. Rather than post a simple print handler here' date=' try a Google search or better yet MSDN, there you'll exactly what you are looking for in a download...I think its called Simple Printing...[/quote'] DiverDan, I don't mean to be rude to you, but "Search Google or MSDN" doesn't constitute an answer in my book. That could be offered as the "answer" to any of the thousands of questions in forums like these, but I don't think it's really what the questioners are looking for. :rolleyes: Quote
Uncle Gizmo Posted March 7, 2004 Posted March 7, 2004 "Search Google or MSDN" doesn't constitute an answer I like this forum; it�s one of the best forums on NET stuff I�ve seen, as a person learning net stuff I am grateful for any help offered. I haven�t read the forums rules, but I think that if a poster just said �search google� Or something similar then that would be unhelpful. But if a user posts a term like �Simple printing� Then that�s exactly what I�m looking for as a beginner, because half the battle is knowing where and what to look for, for the information you require. Supplying some links would be even better. However it is also very nice and extremely helpful to have everything you need posted here. Also this makes the site more useful. As we all know, links can be broken, lost. Microsoft have a bad record of discontinuing useful pages. Quote
kas Posted March 7, 2004 Posted March 7, 2004 II think that if a poster just said �search google� Or something similar then that would be unhelpful. But if a user posts a term like �Simple printing� Then that�s exactly what I�m looking for as a beginner, because half the battle is knowing where and what to look for, for the information you require. Supplying some links would be even better. That's a fair point. In fact, following your post I ran a Google search on that term - "Simple printing" and within four or five searches found a very comprehensive Class from author Karl Moore. The link is here With regard to the "Search on Google/MSDN" responses in general, it's a particular pet hate of mine and I still think that fellow members should post as much information as they are able; but that's just my personal opinion. Quote
*Experts* DiverDan Posted March 7, 2004 *Experts* Posted March 7, 2004 (edited) Wow....Chill guys... Did you ever think that at times one has do...well... work for a living and therefore only has so much time to give???? You might also think about the fact that if that List Box has more than 50 items that your "Print Example" will not work!!! e.HasMorePages with a Statically declared line position (in reference to the printed line's position on the page) has got to be part of the code!!! A Google search for Simple Printing will bring up examples of correctly using the Print Document control. It will also show the individual other ideas and other areas to search for VALID HELP....sort of like teaching....and that give a man a meal vs teaching him him how to farm thing... There have been a lot of responses in this forum about what proper help should be...do a search and find out what others also think about this subject, you might be suprised! Dan Edited March 7, 2004 by DiverDan Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
kas Posted March 7, 2004 Posted March 7, 2004 It's just my personal opinion, Dan. Don't want to escalate it, so won't pick up on your "You might also think about the fact that ..." etc. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.