Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

code for printing entire form

Posted on 2006-06-16
7
Medium Priority
?
394 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 300 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 200 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

This is about my first experience with programming Arduino.
In this post we will learn different types of Android Layout and some basics of an Android App.
Six Sigma Control Plans
Progress

688 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