473,388 Members | 1,322 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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
Jul 10 '06 #1
4 1098
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Programatix | last post by:
Hi, I am working on the PrintDocument, PrintDialog, PageSetupDialog and PrintPreviewControl components of Visual Studio .NET 2003. My developement machine is running Windows XP. There are...
0
by: Programatix | last post by:
Hi, I am working on the PrintDocument, PrintDialog, PageSetupDialog and PrintPreviewControl components of Visual Studio .NET 2003. My developement machine is running Windows XP. There are...
1
by: DCraig | last post by:
I'm having problems printing to a line printer from both Crystal Reports and SQL Server reporting services using dotnet. When I try and print a report from an application with Crystal I get the...
5
by: Stefania Scott | last post by:
I am trying to print a word document from Access. The code I've written works well in my computer but does not in the one were it is needed. Here the piece of code: 'doc path strObjectPath =...
5
by: C-Services Holland b.v. | last post by:
Hi all, I've run into a problem trying to print from vb.net (2002) in Windows 98. To test it I've setup a single form with a button and the following code: 'the form has a button called...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
2
by: Teemu | last post by:
I have an application created with VB6 and now I'm converting it to VB 2005. Conversion is not so simple because printing is so much different. In my app I have Timer-component, which is creates...
2
by: Sukh | last post by:
Hi I am stuck with a problem Can anyone help me out from this... I am printing a report on pre-printed continue paper using dot-matrix printer using vb.net. Data is printing on all the...
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
18
by: Brett | last post by:
I have an ASP.NET page that displays work orders in a GridView. In that GridView is a checkbox column. When the user clicks a "Print" button, I create a report, using the .NET Framework printing...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.