Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Printing Component Advice

Printing Component Advice

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jason Baggett
    wrote on last edited by
    #1

    I have a need to print a Form and its ComboBoxes and Labels by way of a ButtonClick. I found an example to use but it's very vague and I've been told that you can't code a Button in a Form to Print without an aftermarket tool. Any advice? Thanks Jason -- modified at 16:29 Wednesday 7th February, 2007

    X 1 Reply Last reply
    0
    • J Jason Baggett

      I have a need to print a Form and its ComboBoxes and Labels by way of a ButtonClick. I found an example to use but it's very vague and I've been told that you can't code a Button in a Form to Print without an aftermarket tool. Any advice? Thanks Jason -- modified at 16:29 Wednesday 7th February, 2007

      X Offline
      X Offline
      xstoneheartx
      wrote on last edited by
      #2

      here is an easy way: Dim bm As New Bitmap(Me.Width, Me.Height) Dim g As Graphics = Graphics.FromImage(bm) Me.DrawToBitmap(bm, New Rectangle(0, 0, Me.Width, Me.Height)) now you can customize this code to getting a bitmap that only contain client rectangle of your form. another way is: Public Class ScreenCapture _ Private Shared Function GetDesktopWindow() As IntPtr End Function _ Private Shared Function GetWindowDC(ByVal hwnd As IntPtr) As IntPtr End Function _ Private Shared Function BitBlt(ByVal hDestDC As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As IntPtr, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As System.Int32) As UInt64 End Function 'Save the screen capture into a jpg Public Shared Function SaveScreen() As Bitmap Dim myImage = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height) Dim gr1 As Graphics = Graphics.FromImage(myImage) Dim dc1 As IntPtr = gr1.GetHdc() Dim dc2 As IntPtr = ScreenCapture.GetWindowDC(ScreenCapture.GetDesktopWindow()) ScreenCapture.BitBlt(dc1, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc2, 0, 0, 13369376) gr1.ReleaseHdc(dc1) Return myImage End Function 'SaveScreen End Class 'NativeMethods

      J 1 Reply Last reply
      0
      • X xstoneheartx

        here is an easy way: Dim bm As New Bitmap(Me.Width, Me.Height) Dim g As Graphics = Graphics.FromImage(bm) Me.DrawToBitmap(bm, New Rectangle(0, 0, Me.Width, Me.Height)) now you can customize this code to getting a bitmap that only contain client rectangle of your form. another way is: Public Class ScreenCapture _ Private Shared Function GetDesktopWindow() As IntPtr End Function _ Private Shared Function GetWindowDC(ByVal hwnd As IntPtr) As IntPtr End Function _ Private Shared Function BitBlt(ByVal hDestDC As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As IntPtr, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As System.Int32) As UInt64 End Function 'Save the screen capture into a jpg Public Shared Function SaveScreen() As Bitmap Dim myImage = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height) Dim gr1 As Graphics = Graphics.FromImage(myImage) Dim dc1 As IntPtr = gr1.GetHdc() Dim dc2 As IntPtr = ScreenCapture.GetWindowDC(ScreenCapture.GetDesktopWindow()) ScreenCapture.BitBlt(dc1, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc2, 0, 0, 13369376) gr1.ReleaseHdc(dc1) Return myImage End Function 'SaveScreen End Class 'NativeMethods

        J Offline
        J Offline
        Jason Baggett
        wrote on last edited by
        #3

        I tried both methods and the first one was promising, although nothing happened. The Second example gave me a bunch of errors. I found a topic on this very same subject and ended up downloading a ToolPack to get the "PrintForm" component. I set the PrintAction property to PrintToPrinter and put PrintForm1.Print() in the event handler for the Button. This got me the print! Thanks for the help. -- modified at 9:37 Thursday 8th February, 2007

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups