Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

code for printing entire form

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
bryanford
Asked:
bryanford
  • 3
  • 3
2 Solutions
 
alainbrydenCommented:
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
 
bryanfordAuthor Commented:
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
 
alainbrydenCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bryanfordAuthor Commented:
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
 
alainbrydenCommented:
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
 
programmer1024Commented:
0
 
bryanfordAuthor Commented:
A combination of both your posts assisted me with the end result so thankyou very much

sorry for the delay.

Bryan
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now