Solved

make a forms width fit printout

Posted on 2014-10-11
10
76 Views
Last Modified: 2014-10-13
The form is wider than a sheet of paper and not ver tall
I have form that i am trying to avoid making everthing smaller so it can be printed on one sheet of paper
way i see it their are 3 possible solutations
1. redraw all the controls to make them closer together thus making the form more narrow.
Trying to avoid this as many users are using high resolutation and am not sure it will still fit
2. Print the form in Landscape.
Have read where not all printers support Landscape and am not sure if printform can print Landscape
3. Create another form just for printing and copy all the data
Maybe their is another method i have not listed.
Which way would be the best ? and is there another way ?Print problem
0
Comment
Question by:isnoend2001
  • 5
  • 5
10 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40375121
Try this project. If you need help in adding its code to your project please let me know.
Wide.zip
0
 

Author Comment

by:isnoend2001
ID: 40375210
Thanks martinLiss, but nothing happens when i click the buttons and Form1 was not added to the project
0
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40375248
Here is a corrected zip file.
Wide.zip
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 

Author Closing Comment

by:isnoend2001
ID: 40375262
Thanks MartinLiss
I added to print to pdf, so not to waste paper
I will try to modify my project using your code
First thought
does the picturebox cover the whole form with the controls add to the picturebox ?
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40376141
does the picturebox cover the whole form with the controls add to the picturebox ?
Sorry but I'm not sure what that means. In any case you could probably have the picturebox be invisible and still print its contents. If you post a zip of your project (or even just the bids form) then I can probably incorporate the code for you.
0
 

Author Comment

by:isnoend2001
ID: 40376230
Thanks martinLiss
EE would not open earlier tried 4-5 times
I attached the zip
I added a print button to get the printers
I always print to pdf when testing
GetBids.zip
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40377516
This might take an hour or this might take a day, but I'll get back to you.
0
 

Author Comment

by:isnoend2001
ID: 40377750
no problem
Thank you
0
 

Author Comment

by:isnoend2001
ID: 40378050
Hi MartinLiss i got this code from another site

in bas module
Option Explicit

Private Type GUID
    Data1    As Long
    Data2    As Integer
    Data3    As Integer
    Data4(7) As Byte
End Type

Private Type PicBmp
    Size As Long
    Type As Long
    hBitmap As Long
    hPal As Long
    Reserved As Long
End Type

Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, iPic As IPicture) As Long



Public Function FormToPrint(MyForm As Form) As Picture
Dim FormWidth     As Long
Dim FormHeight    As Long
Dim SourceDC      As Long
Dim MemoryDC      As Long
Dim hBitmap       As Long
Dim hBitmapTemp   As Long

With MyForm
  FormWidth = .ScaleX(.ScaleWidth, .ScaleMode, vbPixels)
  FormHeight = .ScaleY(.ScaleHeight, .ScaleMode, vbPixels)
End With

  SourceDC = MyForm.hdc
  MemoryDC = CreateCompatibleDC(SourceDC)
  hBitmap = CreateCompatibleBitmap(SourceDC, FormWidth, FormHeight)
  hBitmapTemp = SelectObject(MemoryDC, hBitmap)

  BitBlt MemoryDC, 0, 0, FormWidth, FormHeight, SourceDC, 0, 0, vbSrcCopy

  hBitmap = SelectObject(MemoryDC, hBitmapTemp)
 
  DeleteDC MemoryDC
  ReleaseDC MyForm.hwnd, SourceDC

Set FormToPrint = CreateBitmap(hBitmap)
End Function


Private Function CreateBitmap(ByVal hBitmap As Long) As Picture
Dim PIC           As PicBmp
Dim iPic          As IPicture
Dim IID_IDispatch As GUID

  With IID_IDispatch
      .Data1 = &H20400
      .Data4(0) = &HC0
      .Data4(7) = &H46
  End With
 
  With PIC
      .Size = Len(PIC)
      .Type = vbPicTypeBitmap
      .hBitmap = hBitmap
  End With
 
  OleCreatePictureIndirect PIC, IID_IDispatch, 1, iPic

Set CreateBitmap = iPic
End Function


Calling the function:

Sub PrintGetBids()
 Dim Percentage As Double

Percentage = 75 '50 'Set Image scale %
Percentage = Percentage / 100

Printer.ScaleMode = vbTwips
frmPrintGetBids.ScaleHeight
Printer.PaintPicture FormToPrint(frmPrintGetBids), 0, 0, Percentage * frmPrintGetBids.ScaleWidth, Percentage *
Printer.EndDoc
End Sub


This seems to work for the sizing, however Ihave ran into another problem
I will post it in another question
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40378135
Before you do that try this project. (You'll need to add the dat file).
Q-28535877.zip
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB 6.0 printer how to align 6 67
MsgBox 2 59
How to read File Date Created using VB6 8 52
Error with a code discussed on this page 5 32
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

829 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