Solved

code for printing entire form

Posted on 2006-06-16
7
363 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

863 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

22 Experts available now in Live!

Get 1:1 Help Now