473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Printing in VB6

Hi,

Does anyone know how print an entire form in Visual Basic 6? I need to be able to resize the form so it prints on one page.
Jul 5 '07 #1
13 1746
jeffbroodwar
118 100+
Hi,

Try form1.printform. But before executing this, change the form color to white. So that it will not waste ink... ^^

Regards,
Jeff
Jul 6 '07 #2
Killer42
8,435 Expert 8TB
Yes, it really comes down to one of two choices - PrintForm, or "roll your own". Though I do recall from some years back that creating your own equivalent of PrintForm is not that hard. The problem with PrintForm, of course, is that (if I remember correctly) it prints at screen resolution, and loses lots of detail. By running through the controls on the form and printing them yourself, I think you can get around that.

(Or maybe you can buy some sort of printing software that will handle it, but that seems rather a waste.)
Jul 6 '07 #3
Hi,

I tried the PrintForm but it cuts off half of my form. You suggested for me to create my own equivalent to PrintForm, do you have any ideas how to go about that? I tried looking for examples online but couldn't really find anything that would fit my needs.


Yes, it really comes down to one of two choices - PrintForm, or "roll your own". Though I do recall from some years back that creating your own equivalent of PrintForm is not that hard. The problem with PrintForm, of course, is that (if I remember correctly) it prints at screen resolution, and loses lots of detail. By running through the controls on the form and printing them yourself, I think you can get around that.

(Or maybe you can buy some sort of printing software that will handle it, but that seems rather a waste.)
Jul 10 '07 #4
To be more specific about my problem I will paste some sample code that I am using:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.  
  3.    Form1.PrintForm
  4.  
  5. End Sub
  6.  
  7. Private Sub Form_Load()
  8.  
  9.   MSFlexGrid1.Width = 5870
  10.   MSFlexGrid1.Top = 840
  11.   MSFlexGrid1.Left = 4800
  12.   MSFlexGrid1.Height = 11655
  13.  
  14.   MSFlexGrid1.Col = 2
  15.   MSFlexGrid1.Row = 23
  16.   MSFlexGrid1.CellBackColor = &HFFFFC0
  17.   'initial settings when form is loaded
  18.   Label1.FontSize = 23
  19.   Label1.Caption = "Data"
  20.   Label1.FontName = "Times New Roman"
  21.   Label1.BackColor = &H8000000F
  22.   'Label2.Alignment = 0
  23.   Label1.Width = MSFlexGrid1.Width
  24.   Label1.Height = 600
  25.   Label1.Top = MSFlexGrid1.Top - 100 - Label1.Height
  26.   Label1.ForeColor = &HFF&
  27.  
  28.   Label2.Caption = "TEST"
  29.   Label2.FontSize = 20
  30.   Label2.FontName = "Times New Roman"
  31.   Label2.Alignment = 0
  32.   Label2.Width = 4250
  33.   Label2.Height = 450
  34.   Label2.Top = MSFlexGrid1.Top + MSFlexGrid1.Height
  35.   Label2.ForeColor = &HFF&
  36.   Label2.BackColor = &H8000000F
  37.  
  38.   For i = 0 To 23
  39.     MSFlexGrid1.RowHeight(i) = 2 * MSFlexGrid1.RowHeight(i)
  40.   Next i
  41.  
  42.   For i = 0 To 3
  43.     MSFlexGrid1.ColWidth(i) = 1.5 * MSFlexGrid1.ColWidth(i)
  44.   Next i
  45.  
  46.   MSFlexGrid1.TextMatrix(0, 1) = "Size range"
  47.   MSFlexGrid1.TextMatrix(0, 2) = "m"
  48.   MSFlexGrid1.TextMatrix(0, 3) = "a"
  49.   MSFlexGrid1.TextMatrix(1, 0) = "d"
  50.   MSFlexGrid1.TextMatrix(1, 1) = "k"
  51.   MSFlexGrid1.TextMatrix(1, 2) = "s"
  52.   MSFlexGrid1.TextMatrix(1, 3) = "t"
  53.   MSFlexGrid1.TextMatrix(23, 1) = "Sum"
  54.  
  55. End Sub
  56.  
  57. Private Sub Form_Resize()
  58.   'make sure everything is centered when form is resized
  59.  
  60.   Label1.Left = (Form1.Width / 2) - (Label1.Width / 2)
  61.   MSFlexGrid1.Left = (Form1.Width / 2) - (MSFlexGrid1.Width / 2)
  62.   Label2.Left = MSFlexGrid1.Left
  63.  
  64. End Sub
I have one MSFlexGrid that has 24 rows and 4 columns and I have 2 labels and one Print button. I want to print it exacly as shown on the screen once the program is run.


Yes, it really comes down to one of two choices - PrintForm, or "roll your own". Though I do recall from some years back that creating your own equivalent of PrintForm is not that hard. The problem with PrintForm, of course, is that (if I remember correctly) it prints at screen resolution, and loses lots of detail. By running through the controls on the form and printing them yourself, I think you can get around that.

(Or maybe you can buy some sort of printing software that will handle it, but that seems rather a waste.)
Jul 10 '07 #5
Killer42
8,435 Expert 8TB
I did see a sample to print all the controls on a form, probably more than ten years ago now. At lunch time (maybe 4 hours from now) I'll see whether I can find (or create) something.
Jul 10 '07 #6
Killer42
8,435 Expert 8TB
Sorry, nothing yet. Stay tuned...
Jul 11 '07 #7
Killer42
8,435 Expert 8TB
I've found a print preview example for VB which provides some helpful info, but not the actual printform equivalent. I know I had one somewhere...
Jul 11 '07 #8
I've found a print preview example for VB which provides some helpful info, but not the actual printform equivalent. I know I had one somewhere...
Have you found anything? I've been looking and can't find too much.
Jul 12 '07 #9
Killer42
8,435 Expert 8TB
Have you found anything? I've been looking and can't find too much.
Not yet - sorry. Might have to build one. I was just thinking of a loop through the controls on the form, printing each of them to the printer. The difficulaties, I suppose, would lie in how to reproduce the look of things like textboxes whose text is longer than the box.

Keep looking though, I'm sure there's already something out there - I know I saw it, early in my VB days (probably more than 10 years ago).
Jul 12 '07 #10
Not yet - sorry. Might have to build one. I was just thinking of a loop through the controls on the form, printing each of them to the printer. The difficulaties, I suppose, would lie in how to reproduce the look of things like textboxes whose text is longer than the box.

Keep looking though, I'm sure there's already something out there - I know I saw it, early in my VB days (probably more than 10 years ago).
I decided to try and use the printer object. I have a text box that has a blue background and the text inside is right justified. With the printer object i've only found a way to print the text inside the text box but not the textbox as a whole. Do you have any idea how to do this?
Jul 17 '07 #11
Killer42
8,435 Expert 8TB
I decided to try and use the printer object. I have a text box that has a blue background and the text inside is right justified. With the printer object i've only found a way to print the text inside the text box but not the textbox as a whole. Do you have any idea how to do this?
(Sorry, haven't had a chance to get back to this.)

I suppose you might just have to draw a box, with the appropriate border, and set the fill colour to match the background of the textbox. Probably using a generic "print this textbox" routine. One thing I recall is that back when I was playing around with all this print preview stuff, colour printing wasn't something that had to be considered.

By the way, if you search M$'s website for something like "add print preview to basic application" they have complete code there to implement print preview. They have versions for... um, I think VB3 and VB5. The latter should also work in VB6.

This won't directly solve your form printing problem, but it's very useful to have, and if you are going to build a form print solution, the preview capability will make it much quicker (and cheaper!) to test as you go. One thing I have always found about printing is that it takes a lot of trial and error.
Jul 17 '07 #12
(Sorry, haven't had a chance to get back to this.)

I suppose you might just have to draw a box, with the appropriate border, and set the fill colour to match the background of the textbox. Probably using a generic "print this textbox" routine. One thing I recall is that back when I was playing around with all this print preview stuff, colour printing wasn't something that had to be considered.

By the way, if you search M$'s website for something like "add print preview to basic application" they have complete code there to implement print preview. They have versions for... um, I think VB3 and VB5. The latter should also work in VB6.

This won't directly solve your form printing problem, but it's very useful to have, and if you are going to build a form print solution, the preview capability will make it much quicker (and cheaper!) to test as you go. One thing I have always found about printing is that it takes a lot of trial and error.

Yeah i agree with you there, ALOT OF TRIAL AND ERROR. I did happen to find something on this website :

http://support.microsoft.com/?kbid=161299

It really helps with what I am doing because it can capture the entire client area and fit it to one page when printing. It does come out a little blurry though, do you have any idea why this is? It seems that all the different printing techniques I have tried so far all seem to come out blurry.
Jul 18 '07 #13
Killer42
8,435 Expert 8TB
... It does come out a little blurry though, do you have any idea why this is? It seems that all the different printing techniques I have tried so far all seem to come out blurry.
I believe this is a pretty common problem, related to the relatively low resolution of the screen. Even a pretty basic printer these days will probably produce 300 dots per inch. A typical screen, on the other hand, shows something on the order of 72 dpi (possibly higher nowadays). So obviously in capturing the screen, you aren't going to get the same sort of resolution you're used to seeing printed.

That's why "drawing" things on the printer generally produces much better results than dumping an image direct from the screen.
Jul 19 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jody Gelowitz | last post by:
I am having a problem with printing selected pages. Actually, the problem isn't with printing selected pages as it is more to do with having blank pages print for those pages that have not been...
0
by: Programatix | last post by:
Hi, I am working on the PrintDocument, PrintDialog, PageSetupDialog and PrintPreviewControl components of Visual Studio .NET 2003. My developement machine is running Windows XP. There are...
9
by: Jody Gelowitz | last post by:
I am trying to find the definition of "Safe Printing" and cannot find out exactly what this entitles. The reason is that I am trying to print contents from a single textbox to no avail using the...
4
by: Suzanka | last post by:
Hello, I have an application written in C# on visual studio .NET. It is a web aplication. The application consists of many different forms, that users occassionaly want to print out for filing....
4
by: Arif | last post by:
I C# code prints very slow as compared to a third party barcode printing software. That software prints approximately 10 labels in 2 seconds while my C# code prints 10 labels in 5 to 6 seconds. And...
6
by: Siv | last post by:
Hi, I am getting into printing with VB.NET 2005 and want to implement the usual capability that a user can select a selection of pages. I have a report that is generated by my application that if...
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
0
by: nikhilgargi | last post by:
Requirement: I need to provide printing capability in a C# desktop application that I am developing The documents that need to be printed can be in Rich Text Format (RTF) or HTML. Custom...
18
by: Brett | last post by:
I have an ASP.NET page that displays work orders in a GridView. In that GridView is a checkbox column. When the user clicks a "Print" button, I create a report, using the .NET Framework printing...
0
it0ny
by: it0ny | last post by:
Hi guys, thanks I am fairly new to this forum so I hope I chose the right place to post this question. I try to make my program printout a deposit's report. I created a class to store the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.