Results 1 to 2 of 2

Thread: Printing form controls using VB

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    2

    Question Printing form controls using VB

    I am using the flex grid control on which I have loaded picture boxs and these picture boxs further have text boxs to display the text. Both the picture boxes and Text boxes are loaded dynamically. The problem is while printing only flex grid gets printed. I am unable to print picture boxes and text boxes. Any solution?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Try this
    VB Code:
    1. ' Prntform sample from BlackBeltVB.com
    2. ' [url]http://blackbeltvb.com[/url]
    3. '
    4. ' Written by Matt Hart
    5. ' Copyright 1999 by Matt Hart
    6. '
    7. ' This software is FREEWARE. You may use it as you see fit for
    8. ' your own projects but you may not re-sell the original or the
    9. ' source code. Do not copy this sample to a collection, such as
    10. ' a CD-ROM archive. You may link directly to the original sample
    11. ' using "http://blackbeltvb.com/prntform.htm"
    12. '
    13. ' No warranty express or implied, is given as to the use of this
    14. ' program. Use at your own risk.
    15. '
    16. ' This sample utilizes a better method than "PrintForm" to print the contents of
    17. ' a Form. PrintForm sometimes excludes grid and other controls. This method simulates
    18. ' pressing the PrintScrn key, which copies the image of either the form or screen to
    19. ' the clipboard. Note that I call the .Clear method of the Clipboard first - that's because
    20. ' it might already have text or something on it.
    21. '
    22. ' When printing, note that I scale the picture's height to proportionally fit the
    23. ' printer's resolution. The procedure would need to be adjusted if the Height of the
    24. ' Form/Screen was greater than Printer.ScaleHeight, or if the Height was greater than
    25. ' the Width and the Width was greater than Printer.ScaleWidth.
    26. '
    27. ' Updated with VK_MENU keypresses - note that NT needs these.
    28.  
    29. Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    30. Private Const VK_MENU As Byte = &H12
    31. Private Const VK_SNAPSHOT As Byte = &H2C
    32. Private Const KEYEVENTF_KEYUP = &H2
    33.  
    34. Private Sub cmdPrintForm_Click()
    35. Dim lWidth As Long, lHeight As Long
    36.     Clipboard.Clear
    37.     Call keybd_event(VK_MENU, 0, 0, 0)
    38.     Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
    39.     DoEvents
    40.     Call keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0)
    41.     Call keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0)
    42.     Printer.Print
    43.     If Width > Printer.ScaleWidth Then
    44.         lWidth = Printer.ScaleWidth
    45.         lHeight = (Printer.ScaleWidth / Width) * Height
    46.     Else
    47.         lWidth = Width
    48.         lHeight = Height
    49.     End If
    50.     Printer.PaintPicture Clipboard.GetData, 0, 0, lWidth, lHeight
    51.     Printer.EndDoc
    52. End Sub

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