Printing problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aristotelis Pitaridis

    #1

    Printing problem

    I was trying to print some information such a way that the user will be able
    to move objects with the mouse on a form, and then I will use the contents
    of the form in order to print the information. Does anyone knows how to
    convert the contents of the form (including labels, textbox, etc...) to a
    bitmap in order to send it to the printer?

    Aristotelis


  • JR

    #2
    Re: Printing problem

    Someone have givven me this code.

    It convert the screen completeet into a bitmap and that print the bitmap
    from memory



    '--------------------------------------start
    code--------------------------------------------

    Private Declare Function BitBlt Lib "gdi32.dll" Alias "BitBlt" (ByVal _

    hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As _

    Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal _

    hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, _

    ByVal dwRop As System.Int32) As Long

    Dim memoryImage As Bitmap

    Private Sub CaptureScreen()

    Dim mygraphics As Graphics = Me.CreateGraphi cs()

    Dim s As Size = Me.Size

    memoryImage = New Bitmap(s.Width, s.Height, mygraphics)

    Dim memoryGraphics As Graphics = Graphics.FromIm age(memoryImage )

    Dim dc1 As IntPtr = mygraphics.GetH dc

    Dim dc2 As IntPtr = memoryGraphics. GetHdc

    BitBlt(dc2, 0, 0, Me.ClientRectan gle.Width, _

    Me.ClientRectan gle.Height, dc1, 0, 0, 13369376)

    mygraphics.Rele aseHdc(dc1)

    memoryGraphics. ReleaseHdc(dc2)

    End Sub

    Private Sub PrintDocument1_ PrintPage(ByVal sender As System.Object, ByVal e
    As System.Drawing. Printing.PrintP ageEventArgs) Handles
    PrintDocument1. PrintPage

    e.Graphics.Draw Image(memoryIma ge, 0, 0,
    PrintDocument1. DefaultPageSett ings.Bounds.Wid th,
    PrintDocument1. DefaultPageSett ings.Bounds.Hei ght)

    End Sub

    Private Sub mnuPrint_Click( ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles mnuPrint.Click

    Dim dlg As New PrintPreviewDia log

    Dim ps As New PrintDialog

    Me.BackColor = Color.White

    Me.Refresh()

    Application.DoE vents()

    CaptureScreen()

    With ps

    PrintDocument1. DefaultPageSett ings.Landscape = True

    ..PrinterSettin gs = PrintDocument1. PrinterSettings

    ps.ShowDialog()

    PrintDocument1. PrinterSettings = .PrinterSetting s

    End With

    With dlg

    ..Document = PrintDocument1

    ..ShowDialog()

    End With

    Me.BackColor = Color.FromKnown Color(KnownColo r.Control)

    End Sub

    '--------------------------------------End
    code--------------------------------------------

    "Aristoteli s Pitaridis" <pitaridis@hotm ail.comschreef in bericht
    news:1152559887 .494996@athnrd0 2...
    >I was trying to print some information such a way that the user will be
    >able to move objects with the mouse on a form, and then I will use the
    >contents of the form in order to print the information. Does anyone knows
    >how to convert the contents of the form (including labels, textbox, etc...)
    >to a bitmap in order to send it to the printer?
    >
    Aristotelis
    >

    Comment

    • Dennis

      #3
      RE: Printing problem

      Can you get the form's graphic object and save it to a bitmap?
      --
      Dennis in Houston


      "Aristoteli s Pitaridis" wrote:
      I was trying to print some information such a way that the user will be able
      to move objects with the mouse on a form, and then I will use the contents
      of the form in order to print the information. Does anyone knows how to
      convert the contents of the form (including labels, textbox, etc...) to a
      bitmap in order to send it to the printer?
      >
      Aristotelis
      >
      >
      >

      Comment

      • Aristotelis Pitaridis

        #4
        Re: Printing problem

        Thanks JR. It works. The only problem is that the quality of the text is not
        very good. Is there any way to improve the quality?

        Aristotelis

        Ï "JR" <x.x@x.x.Ýãñá øå óôï ìÞíõìá
        news:C4ysg.5297 56$dL5.12945535 @phobos.telenet-ops.be...
        >
        Someone have givven me this code.
        >
        It convert the screen completeet into a bitmap and that print the bitmap
        from memory
        >
        >
        >
        '--------------------------------------start
        code--------------------------------------------
        >
        Private Declare Function BitBlt Lib "gdi32.dll" Alias "BitBlt" (ByVal _
        >
        hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As _
        >
        Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal _
        >
        hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
        >
        ByVal dwRop As System.Int32) As Long
        >
        Dim memoryImage As Bitmap
        >
        Private Sub CaptureScreen()
        >
        Dim mygraphics As Graphics = Me.CreateGraphi cs()
        >
        Dim s As Size = Me.Size
        >
        memoryImage = New Bitmap(s.Width, s.Height, mygraphics)
        >
        Dim memoryGraphics As Graphics = Graphics.FromIm age(memoryImage )
        >
        Dim dc1 As IntPtr = mygraphics.GetH dc
        >
        Dim dc2 As IntPtr = memoryGraphics. GetHdc
        >
        BitBlt(dc2, 0, 0, Me.ClientRectan gle.Width, _
        >
        Me.ClientRectan gle.Height, dc1, 0, 0, 13369376)
        >
        mygraphics.Rele aseHdc(dc1)
        >
        memoryGraphics. ReleaseHdc(dc2)
        >
        End Sub
        >
        Private Sub PrintDocument1_ PrintPage(ByVal sender As System.Object, ByVal
        e As System.Drawing. Printing.PrintP ageEventArgs) Handles
        PrintDocument1. PrintPage
        >
        e.Graphics.Draw Image(memoryIma ge, 0, 0,
        PrintDocument1. DefaultPageSett ings.Bounds.Wid th,
        PrintDocument1. DefaultPageSett ings.Bounds.Hei ght)
        >
        End Sub
        >
        Private Sub mnuPrint_Click( ByVal sender As System.Object, ByVal e As
        System.EventArg s) Handles mnuPrint.Click
        >
        Dim dlg As New PrintPreviewDia log
        >
        Dim ps As New PrintDialog
        >
        Me.BackColor = Color.White
        >
        Me.Refresh()
        >
        Application.DoE vents()
        >
        CaptureScreen()
        >
        With ps
        >
        PrintDocument1. DefaultPageSett ings.Landscape = True
        >
        .PrinterSetting s = PrintDocument1. PrinterSettings
        >
        ps.ShowDialog()
        >
        PrintDocument1. PrinterSettings = .PrinterSetting s
        >
        End With
        >
        With dlg
        >
        .Document = PrintDocument1
        >
        .ShowDialog()
        >
        End With
        >
        Me.BackColor = Color.FromKnown Color(KnownColo r.Control)
        >
        End Sub
        >
        '--------------------------------------End
        code--------------------------------------------
        >
        "Aristoteli s Pitaridis" <pitaridis@hotm ail.comschreef in bericht
        news:1152559887 .494996@athnrd0 2...
        >>I was trying to print some information such a way that the user will be
        >>able to move objects with the mouse on a form, and then I will use the
        >>contents of the form in order to print the information. Does anyone knows
        >>how to convert the contents of the form (including labels, textbox,
        >>etc...) to a bitmap in order to send it to the printer?
        >>
        >Aristotelis
        >>
        >
        >

        Comment

        • Aristotelis Pitaridis

          #5
          Re: Printing problem

          Sorry JR but I found an other problem. If an other window exists over the
          form that I want to print, the area of the top level form will be print. I
          think that this is an other problem problem.

          Aristotelis

          Ï "Aristoteli s Pitaridis" <pitaridis@hotm ail.comÝãñáøå óôï ìÞíõìá
          news:1152594518 .879454@athnrd0 2...
          >
          Thanks JR. It works. The only problem is that the quality of the text is
          not very good. Is there any way to improve the quality?
          >
          Aristotelis
          >
          Ï "JR" <x.x@x.x.Ýãñá øå óôï ìÞíõìá
          news:C4ysg.5297 56$dL5.12945535 @phobos.telenet-ops.be...
          >>
          >Someone have givven me this code.
          >>
          >It convert the screen completeet into a bitmap and that print the bitmap
          >from memory
          >>
          >>
          >>
          >'--------------------------------------start
          >code--------------------------------------------
          >>
          >Private Declare Function BitBlt Lib "gdi32.dll" Alias "BitBlt" (ByVal _
          >>
          >hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As _
          >>
          >Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal _
          >>
          >hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
          >>
          >ByVal dwRop As System.Int32) As Long
          >>
          >Dim memoryImage As Bitmap
          >>
          >Private Sub CaptureScreen()
          >>
          >Dim mygraphics As Graphics = Me.CreateGraphi cs()
          >>
          >Dim s As Size = Me.Size
          >>
          >memoryImage = New Bitmap(s.Width, s.Height, mygraphics)
          >>
          >Dim memoryGraphics As Graphics = Graphics.FromIm age(memoryImage )
          >>
          >Dim dc1 As IntPtr = mygraphics.GetH dc
          >>
          >Dim dc2 As IntPtr = memoryGraphics. GetHdc
          >>
          >BitBlt(dc2, 0, 0, Me.ClientRectan gle.Width, _
          >>
          >Me.ClientRecta ngle.Height, dc1, 0, 0, 13369376)
          >>
          >mygraphics.Rel easeHdc(dc1)
          >>
          >memoryGraphics .ReleaseHdc(dc2 )
          >>
          >End Sub
          >>
          >Private Sub PrintDocument1_ PrintPage(ByVal sender As System.Object, ByVal
          >e As System.Drawing. Printing.PrintP ageEventArgs) Handles
          >PrintDocument1 .PrintPage
          >>
          >e.Graphics.Dra wImage(memoryIm age, 0, 0,
          >PrintDocument1 .DefaultPageSet tings.Bounds.Wi dth,
          >PrintDocument1 .DefaultPageSet tings.Bounds.He ight)
          >>
          >End Sub
          >>
          >Private Sub mnuPrint_Click( ByVal sender As System.Object, ByVal e As
          >System.EventAr gs) Handles mnuPrint.Click
          >>
          >Dim dlg As New PrintPreviewDia log
          >>
          >Dim ps As New PrintDialog
          >>
          >Me.BackColor = Color.White
          >>
          >Me.Refresh()
          >>
          >Application.Do Events()
          >>
          >CaptureScreen( )
          >>
          >With ps
          >>
          >PrintDocument1 .DefaultPageSet tings.Landscape = True
          >>
          >.PrinterSettin gs = PrintDocument1. PrinterSettings
          >>
          >ps.ShowDialog( )
          >>
          >PrintDocument1 .PrinterSetting s = .PrinterSetting s
          >>
          >End With
          >>
          >With dlg
          >>
          >.Document = PrintDocument1
          >>
          >.ShowDialog( )
          >>
          >End With
          >>
          >Me.BackColor = Color.FromKnown Color(KnownColo r.Control)
          >>
          >End Sub
          >>
          >'--------------------------------------End
          >code--------------------------------------------
          >>
          >"Aristoteli s Pitaridis" <pitaridis@hotm ail.comschreef in bericht
          >news:115255988 7.494996@athnrd 02...
          >>>I was trying to print some information such a way that the user will be
          >>>able to move objects with the mouse on a form, and then I will use the
          >>>contents of the form in order to print the information. Does anyone knows
          >>>how to convert the contents of the form (including labels, textbox,
          >>>etc...) to a bitmap in order to send it to the printer?
          >>>
          >>Aristotelis
          >>>
          >>
          >>
          >
          >

          Comment

          Working...