CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Aug 2000
    Posts
    265

    Common Dialog Control

    I am using the ShowPrinter method of the common dialog control, which I thought would print my entire form. I get the printer dialog window, but I do not get anything sent to my printer. What is the trick for this to work?


  2. #2
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Common Dialog Control

    The printer common dialog is for selecting a printer and setting various options. You will have to write your own code for doing the actual printing.

    For instance, to print the entire form, use

    Me.PrintForm

    This will print to the printer that the user selected via your printer common dialog (or to the default printer on your system even if you don't show the printer dialog box).

    To print text, you would use the Print method, whereas to print other graphics, you would use Printer.PaintPicture.


  3. #3
    Join Date
    Aug 2000
    Posts
    265

    Re: Common Dialog Control

    Is there a way to print the contents of a listbox that scrolls vertically?


  4. #4
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Common Dialog Control


    for i = 0 to List1.ListCount-1
    print List1.List(i)
    next





  5. #5
    Join Date
    Aug 2000
    Posts
    265

    Re: Common Dialog Control

    This code prints to the form--not the printer. Is there a way to print the listbox contents to the printer?


  6. #6
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Common Dialog Control

    Sorry, use

    Printer.Print



  7. #7
    Join Date
    Aug 2000
    Posts
    265

    Re: Common Dialog Control

    There is no print method for the printer object. It only has a printquality property. Am I missing something here?


  8. #8
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Common Dialog Control

    Though IntelliSense doesn't show it (is that a bug?), there's still a Print method for the Picturebox control and the Printer Object. So, go on with it. Only remember to put a Printer.EndDoc at the end of the loop, otherwise your application will start to print after you close your application!


  9. #9
    Join Date
    Aug 2000
    Posts
    265

    Re: Common Dialog Control

    Dim myPrinter As Printer
    Dim n As Integer
    Set myPrinter = Printer
    For n = 0 To List1.ListCount - 1
    myPrinter.Print List1.List(n)
    Next
    Printer.EndDoc

    When I run this code, it bombs at the line myprinter.print



  10. #10
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Common Dialog Control

    It works fine on my system. Do you have a printer installed on your system?


  11. #11
    Join Date
    Aug 2000
    Posts
    265

    Re: Common Dialog Control

    Yes, I do. I'm wondering if our network is set up in a way that prevents this from working.

    Ughh!


  12. #12
    Join Date
    Aug 2000
    Posts
    265

    Re: Common Dialog Control

    Just thought you'd like to know. I took out this line of code printer = commondialog1.PrinterDefault

    Now it works. I cannot understand why that hoses my printer, but I'm just happy that I can print now.

    Thanks for all your help.


  13. #13
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Common Dialog Control

    Good.

    You put the PrinterDefault property to wrong use. This property returns or sets an option that determines if the user's selections in the Print dialog box are used to change the system's default printer settings.

    If you included this line to tell Visual Basic to use the default printer, you do not have to. Visual Basic always uses the default printer to print unless the user chooses to print to a different printer via the print dialog box.


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

Featured