Solved

code for printing entire form

Posted on 2006-06-16
7
351 Views
Last Modified: 2010-05-18
Hello,

I want to print an entire form. I have looked at the other examples on here but i dont have the PrintForm function when i type Me.

Do i have to import anything?
Bryan
0
Comment
Question by:bryanford
  • 3
  • 3
7 Comments
 
LVL 20

Expert Comment

by:alainbryden
ID: 16925458
IF you want to display it, then just loop through each of the form contents with a msgbox, but I'm sure this isn't what you wanted to do or you wouldn't have asked.

IF by print form you mean to use an actual printer, than you need to import the common dialogue box in your components. This is very simple to do, and then you just create a new common dialogue, set the type as PrintDialoge, and then you're off.

If all you want to do is to take a snapshot of a form, like a screenshot type thing, then you need to simulate the pressing of Alt+PrintScreen on the keyboard.  To do this you do the following:

Declare Function keybd_event Lib "user32" Alias "keybd_event" _
     (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, _
     ByVal dwExtraInfo As Long) As Long

so that you can do a keyboard event. THen when you want the screenshot:

keybd_event(VK_Alt, 0, 0, 0) 'send a key
keybd_event(VK_PrintScreen, 0, 0)
keybd_event(VK_Alt, 0, KEYEVENTF_KEYUP, 0) 'release key

Then to store it something like:

frmcontrols.snapImage1.Picture = Clipboard.GetData(vbCFBitmap)
0
 
LVL 1

Author Comment

by:bryanford
ID: 16925463
sorry i should have been more specific.

I want to print it to a printer, but dont want the title bar or border, and sometimes its scrollable so I want it to also print out what you cant see without scrolling.

I am using visual studio 2005 in vb.net language.

Thanks
0
 
LVL 20

Expert Comment

by:alainbryden
ID: 16925560
Ah for starters you'll need to put everything you want into a listbox or a textbox. You need to defined exactly what format to print in. Probably the easiest way to do this would be to export data to a file, or spreadsheet, depending on the format, and then call the command for a print dialogue box for those. It's as easy as ExcelApp.Print
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:bryanford
ID: 16926350
all that is on my form is a bunch of labels. and this program is to be run on a pc without any software installed.
0
 
LVL 20

Accepted Solution

by:
alainbryden earned 75 total points
ID: 16926881
well, no softoware other than your own ;)

Okay, so looks like you need the printer dialogue box.

For example you could Create a rich text box and add all the label's to it in the order and format you want then: use  RichTextBox1.SelPrint (Printer.hDC) to print everything

http://www.samspublishing.com/library/content.asp?b=STY_VB6_24hours&seqNum=124
this will tell you how to get a dialogue box on your form. You need to include the control "Microsoft Common Dialog Control 6.0) or a later version. And this:

cdbDialog.DialogTitle = "Select a Printer"   '(for example)
cdbDialog.ShowPrinter

Will display the printer dialogue box.

There are properties you can set such as:

CommonDialog1.Copies = 2  
CommonDialog1.PrinterDefault = True
a summary of such properties are under the print dialogue heading at the bottom of this site: http://www.raritanval.edu/departments/CIS/full-time/Schwarz/avb/Lesson10.htm

CommonDialog1.flags = ....
here's a list of available flags: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cmdlg98/html/vbproFlagsPrint.asp

Really though you should just give the user as much freedom as he wants.

Once they submit you have tons of data from the form to process.
you can add stuff to the 'to print' list using a Printer object.
To set the printer object up based on the dialogue, you set properties such as Printer.DeviceName = CommonDialog1.name

Printer.Print form2.textbox1
Printer.Print form2.label
Printer.Print "ANd then..."   etc

Nothing will actually print until you have a lone statment.

Printer.Print.

Make sure to have lots of error handling incase the user disconnects from the printer.

This is a taste and there's a more in depth walkthrough of what you can do with a printer here: http://www.samspublishing.com/library/content.asp?b=STY_VB6_24hours&seqNum=166&rl=1

Hope I've been helpful. Let me know if there's any holes to fill. There's a lot of different approaches here.
0
 
LVL 4

Assisted Solution

by:programmer1024
programmer1024 earned 50 total points
ID: 16927990
0
 
LVL 1

Author Comment

by:bryanford
ID: 17046795
A combination of both your posts assisted me with the end result so thankyou very much

sorry for the delay.

Bryan
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
A short article about problems I had with the new location API and permissions in Marshmallow
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now