|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Printing
I have a program that needs to print out tax reciepts from a database and I set it up graphically in a new form the use the printform command but on the machine I'm installing it on the screen area is much smaller and it only prints what fits on the screen... what do i do?
|
|
#2
|
||||
|
||||
|
You either have to make the form fit to the screen (no matter the size of the screen) or print in a different method. Like printing to a file, or using crystal reports (or a reporting tool like that).
Also, your subject title is unacceptable. You can refer to the sticky thread at the top of this forum for more information on how to post a question. |
|
#3
|
|||
|
|||
|
There is no way to make visual basic print a full page of info on a 15inch moniter with 1280x1024 max resolution without using crystal reports then? All right, thanks
|
|
#4
|
|||
|
|||
|
Hi i have the same problem, but i donīt understand how can i print the form to a file or crystal reports???
|
|
#5
|
||||
|
||||
|
well.. can you print an HTML encoded string to the monitor? It would at least give you the ability to print out a marked-up text document
__________________
Fisherman "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein |
|
#6
|
|||
|
|||
|
Print with vb:
Two basic possibilities... 1, reference Word and use the word object to load and print the required document 2, use SHELLECECUTE API to call print the document. If all you want to do is print the doc, I would say option 2 is the easiest way. If you want to do error trapping and other thigns then use #1 example of #2 option... shellexecute 0,"print","c:\windows\desktop\mydoc.doc","","",SW_SHOW This method works for anything that can be printed not just Word Docs. As long as Windows knows how to PRINT that is. Printing with VB Unsurprisingly, Visual Basic provides us with the Printer and Printers objects, which are available at runtime to all VB apps. The Printers object gives us information about all the available printers installed on the system. The Printer object controls all the output to the active printer and retrieves information such as the printer name. First of all, lets look at the basic steps involved in printing with VB. First off, we send all the data we want to print using the Print method. For example, if we wanted to print "Hello", we would call Printer.Print "Hello" Each time you call the Print method, your output will move to the next line. So, Printer.Print "Hello" Printer.Print "Goodbye!" would appear as Hello Goodbye! on paper. If you want to output a new page, you simply call the NewPage method: Printer.NewPage Once you have finished outputting the data to the printer, you need to call the EndDoc method: Printer.EndDoc Windows will then spool your document to the printer. Setting formatting options Using the Printer object further, you can also apply formatting to the text you output by setting the Font and its associated FontSize, FontBold, FontItalic, FontStrikeThru and FontUnderline properties. To change the font, simply change the FontName property. For example, Printer.FontName = "Tahoma" changes the font to Tahoma. To change the size, just call Printer.FontSize. Most of the other formatting options are just boolean (ie True or False), which makes it even easier to apply formatting. The code below gives a simple demonstration: With Printer Printer.Print "Normal Line" .FontBold = True Printer.Print "Bold Line" .FontItalic = True Printer.Print "Bold and Italic Line" .FontBold = False .FontItalic = False Printer.Print "Second Normal Line" .EndDoc End With [Note] Although I am using a With statement, I still have to write Printer.Print for outputting the text. This is another 'quirk' of VB - the Print statement does not actually belong to the Printer object, or in fact any other object in VB. If you search for Print in the Object Browser (press F2), you won't find it anywhere. Print is in fact a statement that VB interprets on its own, and outputs it according to the object before the Print statement. If you call PictureBox1.Print, it will 'print' the text into the PictureBox control. As such, the Print function behaves just as if it were an object of PictureBox or Printer. However, the designers of VB obviously didn't extend this behavior to With statements. [End Note] For a full list of font options, go to the Object Browser (F2), and select Printer from the Classes list. One other thing worth noting regarding formatting... If you are using the RichTextBox control, you don't need to worry about applying all the formatting - there is some code using API calls which does it all for you, including page margins! Click here to see that code. Setting the alignment of text isn't quite so simple because VB doesn't provide an align property. Instead, we need to work out where the middle of the page is and then take into account the width of the text. Take a look at this code, which prints the page number in the middle of the page: sMsg = "Page " & Printer.Page ' Print Page number HWidth = Printer.TextWidth(sMsg) / 2 ' Get one-half width. HHeight = Printer.TextHeight(sMsg) /2 ' Get one-half height. Printer.CurrentX = Printer.ScaleWidth / 2 - HWidth Printer.CurrentY = Printer.ScaleHeight / 2 - HHeight Printer.Print sMsg This code uses the CurrentX and CurrentY variables to change the position of where the text is outputted, centers the position, and prints the page number using the Printer's Page property. If you want the text in the middle at the top of the page, simply comment out the Printer.CurrentY line. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Printing |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|