Solved

how to use print dialog box?

Posted on 2000-05-17
19
305 Views
Last Modified: 2010-05-02
I have created a mdiform, which contains only menu bar. under which one
of the option is print and another is show.
I have created another new form and set the mdichild property to true. The child form is having list view control containing some data. I want to print the data of the list view control.
under the show click event, i am showing the child form which containing list view control.
In the print click event of menu bar i have done dialogbox.showprint. with the click event it is getting displayed but after pressing ok i am not getting any contents of list view control printed.

U please tell me how to tackle this problem.
0
Comment
Question by:rajiv_konx
  • 9
  • 6
  • 2
  • +2
19 Comments
 

Expert Comment

by:rizmughal
ID: 2816846
Please explain in Detail
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2816957
You want to select the active form to do your activity.  For example, suppose frmMDI is your MDI parent and List1 is a ListBox on the child.  Then, you would reach the child ListBox control by:

frmMDI.ActiveForm.List1

0
 
LVL 2

Expert Comment

by:BobbyOwens
ID: 2817026
You can't do it the way you are trying. What you'll need to do is print via the "Printer" object. You will need to programatically go through the listview control and do "Printer.Print", passing in the text you want to print.

The code below should do a basic print of a listview with 3 columns.

e.g.

Private Sub PrintListView()
 
  On Error GoTo PrintListView_Error

  Dim litData         As ListItem
  Dim strToPrint      As String
 
'Process listview
  For Each litData In lvwData.ListItems
'Get string to print (Assuming only 3 columns in listview)
    strToPrint = litData.Text & vbTab & litData.SubItems(1) & vbTab & litData.SubItems(2)
    Printer.Print strToPrint
  Next
'End Print
  Printer.EndDoc
 
PrintListView_Exit:
  Exit Sub
 
PrintListView_Error:
  MsgBox Err.Description, , "PrintListView"
  Resume PrintListView_Exit
 
End Sub


0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 18

Expert Comment

by:mdougan
ID: 2818869
Yes, just to clarify things a bit, the only purpose of the common dialog ShowPrint window is to pop up a dialog that will allow you to get input from the user about how many copies to  print, what pages to print, which printer to use etc.  Then, it's up to you to write the code retreive what the user entered in the dialog and to format the output as Bobby shows and print it.  

VB's built in support for printing is pretty limited, so, if you really need fancy printouts you might consider using Crystal Reports, or maybe a DataReport, or there is a pretty nice control from VideoSoft called VSView which is a sort of replacement for the VB Printer object.  You can download a free demo version of VSView from VideoSoft at

http://www.videosoft.com

it's a great control, but it's a bit pricey too.
0
 

Author Comment

by:rajiv_konx
ID: 2824804
BobbyOwens,
        Thanks for the information. But i want to print the contents in the tabular format. i.e if the list view control has 3 headers then i want a table with 3 columns and as many rows the paper can fit. In the columns i want to print the actual contents of the list items. I will give the sizes of the columns depending on the number of column headers.
 Please help me out of this.
0
 
LVL 2

Accepted Solution

by:
BobbyOwens earned 100 total points
ID: 2824997
What you'll need to do is going to be more complicated. You'll need to use the "CurrentX" property.

First of all, do something like the following (Notice the semicolons so that a new line isn't done every time):

printer.print lvwMain.ColumnHeaders(1).Text;
printer.currentX=50
printer.print lvwMain.ColumnHeaders(2).Text;
printer.currentX=150
printer.print lvwMain.ColumnHeaders(3).Text
printer.currentX=250

The last print statement doesn't have a semicolon at the end because you want the printer to go to a new line. You will need to adjust the "CurrentX" coordinate according to the widths you require. I only uses the numbers above to illustrate moving across the page.  This should print in tabular form but without the gridlines.


0
 
LVL 18

Expert Comment

by:mdougan
ID: 2860508
Again, you might try to download the demo of the VideoSoft VSView Control.  It makes printing tabular or report formats much easier than the Printer object.  The VSView control will handle pagination and allow you to define page headers and footers, margins, fonts and many other items.  If  the thing you're printing happens to be a VideoSoft VSFlex table, then printing it is even easier.
0
 

Author Comment

by:rajiv_konx
ID: 2890264
mdougan,
 i agree that common dialog showprint dialog box is just to take input from the user. I need pages option button to be enabled , so that in the edit boxe's from and to i can enter the page numbers. For this i have set the flag property to cdlPDPageNums. even after doing this pages option is not being enabled. please tell me how to enable the option.
0
 
LVL 2

Expert Comment

by:BobbyOwens
ID: 2891042
This should do the trick:

CommonDialog1.Flags = CommonDialog1.Flags Or cdlPDPageNums
CommonDialog1.Max = 50
CommonDialog1.Min = 0
CommonDialog1.ShowPrinter

You need to set the minimum and maximum pages to print as well
0
 

Author Comment

by:rajiv_konx
ID: 2891080
before obly I have done that but could not succeed with cdlPDPageNums
0
 
LVL 2

Expert Comment

by:BobbyOwens
ID: 2891777
I'm afraid I didn't understand the last comment. Are you saying you've tried that and it didn't work. If so, ensure that you are setting the flags before the max and min.
0
 

Author Comment

by:rajiv_konx
ID: 2938405
BobbyOwens,
       Everything is fine and i am able to print what i wanted. but i am facing problem with print to file check box of the printer dialog box.
      Rather than printing directly i want to print to a file.
please tell me how to go for this.
0
 
LVL 2

Expert Comment

by:BobbyOwens
ID: 2938609
To find the checkbox value, you need to do:

blnChecked = (CommonDialog1.Flags And cdlPDPrintToFile) > 0


Then you need to write code to print to a file in whatever format you want.
0
 

Author Comment

by:rajiv_konx
ID: 2938735
BobbyOwens,
I think u did not get my question properly. I want to print to a file means i want to click the print to file check box in the dialog box,  later i will supply the save dialog box so that he can save that file anywhere. please note that the file generated will be binary file not text file. later he can goto the dos prompt and print the file.

Please see any application having the print option so that u will get clear picture of what i want.
0
 
LVL 2

Expert Comment

by:BobbyOwens
ID: 2939186
What you'll need to do is reopen the common dialog control using the "Save" action. Set the file type as PRN, and filter accordingly.

I don't know how to create a true PRN file. You could create a normal binary file using the "Open" method, but I don't know how you'll get DOS to print the file.
0
 

Author Comment

by:rajiv_konx
ID: 2939262
BobbyOwens,
I think u did not get my question properly. I want to print to a file means i want to click the print to file check box in the dialog box,  later i will supply the save dialog box so that he can save that file anywhere. please note that the file generated will be binary file not text file. later he can goto the dos prompt and print the file.

Please see any application having the print option so that u will get clear picture of what i want.
0
 

Author Comment

by:rajiv_konx
ID: 2939554
I am sorry i want to create true file i.e prn. if u can u pls tell me.
what ever u said i can do only if true prn is created.
0
 

Author Comment

by:rajiv_konx
ID: 3008894
Comment accepted as answer
0
 

Author Comment

by:rajiv_konx
ID: 3008895
Thanks for helping me in solving this problem.
I have got what ever i wanted
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question