By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,719 Members | 1,046 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,719 IT Pros & Developers. It's quick & easy.

Printing problem

P: n/a
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
Jul 10 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
JR
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.CreateGraphics()

Dim s As Size = Me.Size

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

Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)

Dim dc1 As IntPtr = mygraphics.GetHdc

Dim dc2 As IntPtr = memoryGraphics.GetHdc

BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, _

Me.ClientRectangle.Height, dc1, 0, 0, 13369376)

mygraphics.ReleaseHdc(dc1)

memoryGraphics.ReleaseHdc(dc2)

End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e
As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage

e.Graphics.DrawImage(memoryImage, 0, 0,
PrintDocument1.DefaultPageSettings.Bounds.Width,
PrintDocument1.DefaultPageSettings.Bounds.Height)

End Sub

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

Dim dlg As New PrintPreviewDialog

Dim ps As New PrintDialog

Me.BackColor = Color.White

Me.Refresh()

Application.DoEvents()

CaptureScreen()

With ps

PrintDocument1.DefaultPageSettings.Landscape = True

..PrinterSettings = PrintDocument1.PrinterSettings

ps.ShowDialog()

PrintDocument1.PrinterSettings = .PrinterSettings

End With

With dlg

..Document = PrintDocument1

..ShowDialog()

End With

Me.BackColor = Color.FromKnownColor(KnownColor.Control)

End Sub

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

"Aristotelis Pitaridis" <pi*******@hotmail.comschreef in bericht
news:1152559887.494996@athnrd02...
>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

Jul 10 '06 #2

P: n/a
Can you get the form's graphic object and save it to a bitmap?
--
Dennis in Houston
"Aristotelis 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
Jul 10 '06 #3

P: n/a
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.έγραψε στο μήνυμα
news:C4***********************@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.CreateGraphics()

Dim s As Size = Me.Size

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

Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)

Dim dc1 As IntPtr = mygraphics.GetHdc

Dim dc2 As IntPtr = memoryGraphics.GetHdc

BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, _

Me.ClientRectangle.Height, dc1, 0, 0, 13369376)

mygraphics.ReleaseHdc(dc1)

memoryGraphics.ReleaseHdc(dc2)

End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal
e As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage

e.Graphics.DrawImage(memoryImage, 0, 0,
PrintDocument1.DefaultPageSettings.Bounds.Width,
PrintDocument1.DefaultPageSettings.Bounds.Height)

End Sub

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

Dim dlg As New PrintPreviewDialog

Dim ps As New PrintDialog

Me.BackColor = Color.White

Me.Refresh()

Application.DoEvents()

CaptureScreen()

With ps

PrintDocument1.DefaultPageSettings.Landscape = True

.PrinterSettings = PrintDocument1.PrinterSettings

ps.ShowDialog()

PrintDocument1.PrinterSettings = .PrinterSettings

End With

With dlg

.Document = PrintDocument1

.ShowDialog()

End With

Me.BackColor = Color.FromKnownColor(KnownColor.Control)

End Sub

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

"Aristotelis Pitaridis" <pi*******@hotmail.comschreef in bericht
news:1152559887.494996@athnrd02...
>>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


Jul 11 '06 #4

P: n/a
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

Ο "Aristotelis Pitaridis" <pi*******@hotmail.comέγραψε στο μήνυμα
news:1152594518.879454@athnrd02...
>
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.έγραψε στο μήνυμα
news:C4***********************@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.CreateGraphics()

Dim s As Size = Me.Size

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

Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)

Dim dc1 As IntPtr = mygraphics.GetHdc

Dim dc2 As IntPtr = memoryGraphics.GetHdc

BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, _

Me.ClientRectangle.Height, dc1, 0, 0, 13369376)

mygraphics.ReleaseHdc(dc1)

memoryGraphics.ReleaseHdc(dc2)

End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal
e As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage

e.Graphics.DrawImage(memoryImage, 0, 0,
PrintDocument1.DefaultPageSettings.Bounds.Width ,
PrintDocument1.DefaultPageSettings.Bounds.Heigh t)

End Sub

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

Dim dlg As New PrintPreviewDialog

Dim ps As New PrintDialog

Me.BackColor = Color.White

Me.Refresh()

Application.DoEvents()

CaptureScreen()

With ps

PrintDocument1.DefaultPageSettings.Landscape = True

.PrinterSettings = PrintDocument1.PrinterSettings

ps.ShowDialog()

PrintDocument1.PrinterSettings = .PrinterSettings

End With

With dlg

.Document = PrintDocument1

.ShowDialog()

End With

Me.BackColor = Color.FromKnownColor(KnownColor.Control)

End Sub

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

"Aristotelis Pitaridis" <pi*******@hotmail.comschreef in bericht
news:1152559887.494996@athnrd02...
>>>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



Jul 11 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.