Results 1 to 16 of 16

Thread: Print a listbox? [Resolved]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665

    Question Print a listbox? [Resolved]

    When I try to print out this it dosen't look as straight and nice as it looks in the listbox. Why?
    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    2. Private Const LB_SETTABSTOPS = &H192
    3.  
    4. Private Sub Form_Load()
    5. ReDim TabStop(0 To 2) As Long
    6.  
    7.   'assign some values to the tabs for the second third and fourth
    8.   'column (the first is flush against the listbox edge)
    9.    TabStop(0) = 20
    10.    TabStop(1) = 70
    11.    TabStop(2) = 200
    12.  
    13.    
    14.    List1.Clear
    15.   'clear then set the tabs
    16.  
    17.    Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 0&, ByVal 0&)
    18.    Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 3, TabStop(0))
    19.    
    20.     List1.AddItem "Test text" & Chr(9) & "Test Date 0301" & Chr(9) & "MaterialNumber"
    21.     List1.AddItem "Test text 2" & Chr(9) & "Test Date 030104" & Chr(9) & "MaterialNumber"
    22.     List1.AddItem "Test text 3" & Chr(9) & "Test Date 20030301" & Chr(9) & "MaterialNumber"
    23.     List1.AddItem "Test text 4" & Chr(9) & "Test Date Wednesday 04:00 Pm" & Chr(9) & "MaterialNumber"
    24. End Sub
    25.  
    26. Private Sub Command1_Click()
    27.     Dim x As Integer
    28.    
    29.     For x = 0 To List1.ListCount - 1
    30.     Printer.Print List1.List(x)
    31.     Next x
    32. Printer.EndDoc
    33. End Sub
    Last edited by Pirre001; Mar 3rd, 2004 at 02:06 PM.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    You have not set any TabStops for the printer (Can you even set TabStops for a printer?).

    TabStops are a formatting function. The original data does not change. The Listbox simply moves to the specified column whenever it encounters a Tab character. It does not add spaces.

    Try the DrawText API - I know it supports TabStops.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665
    Thanks brucevde,

    Can you show me a example?

  4. #4
    Lively Member
    Join Date
    Jan 2003
    Posts
    79
    I've run your code and I see what you mean.
    I think the problem is that the tabstops you have set in the listbox are not sent to the printer; only the tab characters that you have entered into the listbox text are applied to the printed format.

    Hope this helps.

    All the best,

    Dave.

    P.S. Sorry for the cross post Brucevde

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665
    Dave Bleby,

    I have tried that, but I it doesn't work for me. Can you show me a working example?

  6. #6

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665
    Ok MartinLiss,

    And how do I do this with a ListView?

    If I wanna use a listbox, do you have anu solution to do that also?
    Last edited by Pirre001; Mar 3rd, 2004 at 03:44 AM.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665
    I really need help with this...

  9. #9
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871
    Here's an example of how to use a ListView in your case. Add Microsoft Windows Common Controls 6 to your project. I haven't tested the printing with a listview though.
    Attached Files Attached Files
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665
    Thanks TheVader,

    But I need a working print example with a listbox

  11. #11

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665
    Thanks MartinLiss,

    Can u show me a working example of printing from a listbox, as I described?

  13. #13
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    It would be similar.

    VB Code:
    1. Dim lngIndex As Long
    2.     Dim strParts() As String
    3.    
    4.     ' Print the data
    5.     For lngIndex = 0 To List1.ListCount - 1
    6.         strParts = Split(List1.List(lngIndex), vbTab)
    7.         Printer.Print strParts(0); Tab(30); strParts(1); Tab(100); strParts(2)
    8.        
    9.     Next
    10.    
    11.     Printer.EndDoc

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665
    Thanks again MartinLiss,

    another question,

    Does Mscomctl.ocx (Windows Common Controls 6) includes in Windows 2000 as default or do I include this file in my setupprogram?

  15. #15

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665
    Thanks Marty!

    You have solved my problems.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width