Results 1 to 10 of 10

Thread: [RESOLVED] How to print form?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [RESOLVED] How to print form?

    I have textbox, picture box . How I can print the form?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to print form?

    vb Code:
    1. Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
    2. ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    3.  
    4. Private Const VK_MENU As Byte = &H12
    5. Private Const VK_SNAPSHOT As Byte = &H2C
    6. Private Const KEYEVENTF_KEYUP = &H2
    7.  
    8. Private Sub cmdPrintForm_Click()
    9. Dim lWidth As Long, lHeight As Long
    10.     Clipboard.Clear
    11.     Call keybd_event(VK_MENU, 0, 0, 0)
    12.     Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
    13.     DoEvents
    14.     Call keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0)
    15.     Call keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0)
    16.     Printer.Print
    17.     If Width > Printer.ScaleWidth Then
    18.         lWidth = Printer.ScaleWidth
    19.         lHeight = (Printer.ScaleWidth / Width) * Height
    20.     Else
    21.         lWidth = Width
    22.         lHeight = Height
    23.     End If
    24.     Printer.PaintPicture Clipboard.GetData, 0, 0, lWidth, lHeight
    25.     Printer.EndDoc
    26. End Sub

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to print form?

    How I can modify the code?

    It print the whole in the form including the control box and command button.
    Attached Images Attached Images  

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: How to print form?

    Don't forms have a PrintForm method that you can use?

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to print form?

    Sometimes printform does print controls like grids or picture boxes.

    It does print the whole form. That is what I thought you asked for.

    All you want to do is print the text within the textbox and the picture within the picture box?

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to print form?

    All you want to do is print the text within the textbox and the picture within the picture box?
    Yes.

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to print form?

    How about
    Code:
    Printer.Print Text1.Text
    Printer.Print Picture1.Picuture
    Printer.EndDoc

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to print form?

    Review the Printer object in the Object Browser to see all its functions and methods etc. You will see there are all kinds of thigs you can manipulate with it. To choose the printer it will be printed to you will need to add a commondialog control to your form and execute the .ShowPrinter method to present the user with a list of printers they can choose from. Then assign the selection to the Printer object relevant property.

    You may have also wanted to choose a better thread title as you would have gotten more direct replies

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to print form?

    Quote Originally Posted by RobDog888
    To choose the printer it will be printed to you will need to add a commondialog control to your form and execute the .ShowPrinter method to present the user with a list of printers they can choose from. Then assign the selection to the Printer object relevant property.
    I use common dialog box. How I can execute the selected printer devices and assign the selected printer to print the paper?

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to print form?

    Commondialog1.ShowPrinter.
    Then after the selections have been made you can read what was selected and assign to the Printer object correcponding properties.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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