Results 1 to 6 of 6

Thread: Print Form

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    33

    Red face Print Form

    Hi,
    I want to print a form as it is to the printer and the form is hidden from the user. I tried using PrintForm method but it behaves weird in some
    situations. I want to know if anyother method could be used. All I've in the form is a frame and 3 labels and 3 text
    boxes. Thanks for the help
    Reflex

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    I've replaced the standard Me.PrintForm in all my projects with this little ditty that I got from www.blackbeltvb.com

    I've never tried it with a hidden form, but I don't see why it wouldn't work.

    Let me know.

    Prntform sample from BlackBeltVB.com
    ' http://blackbeltvb.com
    '
    ' Written by Matt Hart
    ' Copyright 1999 by Matt Hart
    '
    ' This software is FREEWARE. You may use it as you see fit for
    ' your own projects but you may not re-sell the original or the
    ' source code. Do not copy this sample to a collection, such as
    ' a CD-ROM archive. You may link directly to the original sample
    ' using "http://blackbeltvb.com/prntform.htm"
    '
    ' No warranty express or implied, is given as to the use of this
    ' program. Use at your own risk.
    '
    ' This sample utilizes a better method than "PrintForm" to print the contents of
    ' a Form. PrintForm sometimes excludes grid and other controls. This method simulates
    ' pressing the PrintScrn key, which copies the image of either the form or screen to
    ' the clipboard. Note that I call the .Clear method of the Clipboard first - that's because
    ' it might already have text or something on it.
    '
    ' When printing, note that I scale the picture's height to proportionally fit the
    ' printer's resolution. The procedure would need to be adjusted if the Height of the
    ' Form/Screen was greater than Printer.ScaleHeight, or if the Height was greater than
    ' the Width and the Width was greater than Printer.ScaleWidth.
    '
    ' Updated with VK_MENU keypresses - note that NT needs these.

    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    Private Const VK_MENU As Byte = &H12
    Private Const VK_SNAPSHOT As Byte = &H2C
    Private Const KEYEVENTF_KEYUP = &H2


    Dim lWidth As Long, lHeight As Long
    Clipboard.Clear
    Call keybd_event(VK_MENU, 0, 0, 0)
    Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
    DoEvents
    Call keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0)
    Call keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0)
    Printer.Print
    If Width > Printer.ScaleWidth Then
    lWidth = Printer.ScaleWidth
    lHeight = (Printer.ScaleWidth / Width) * Height
    Else
    lWidth = Width
    lHeight = Height
    End If
    Printer.PaintPicture Clipboard.GetData, 0, 0, lWidth, lHeight
    Printer.EndDoc

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    33

    Wink Thanks, but that doesnt work for my case

    Thanks for the reply. I did try this code from blackbelt vb.com too. The problem is it prints whatever window has the focus at execution time. I tried it many ways to execute as a .exe file too. It printed the Windows Exploere once, believe it. And in my case I cannot set the focus to my form to be the active window, because I want to hide it and then print it for the user. Another different form has the focus at that moment. Please help me. Thanks,
    Reflex.

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    33

    Hellooooo!!!

    Can anyone help me with this PrintForm, please? Its kind of stucking me up and any help is greatly appreciated. I didnt hear from any of you...Thanks

  5. #5
    New Member
    Join Date
    Aug 2001
    Posts
    3
    try this
    load form1
    form1.hide
    form1.printform

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    33
    Thanks for the reply but PrintFrom method is the one causing me problem as it doesnt work well in all cases. I want any other method than Print Form. Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width