Solved

make a forms width fit printout

Posted on 2014-10-11
10
70 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 45

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 45

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40375248
Here is a corrected zip file.
Wide.zip
0
 

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 45

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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 45

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 45

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

759 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

21 Experts available now in Live!

Get 1:1 Help Now