PC Review


Reply
Thread Tools Rate Thread

Printing a form with VB.Net

 
 
Hotrod2000
Guest
Posts: n/a
 
      8th Mar 2010
I'am trying to print a windows form with the following code, but keep
getting this error message (posted below code).
My form has a few unused labels on in and a print button (Button1)

Any help would be greatly appreiciated :-

Public Class Form1

Private WithEvents pd As Printing.PrintDocument
Dim formImage As Bitmap
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 hdcScr As IntPtr, ByVal nXSrc As Integer, ByVal NySrc As
Integer, ByVal dwRop As System.Int32) As Long


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
pd = New Printing.PrintDocument
Me.StartPosition = FormStartPosition.CenterScreen
End Sub
Private Sub pd_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles pd.PrintPage
e.Graphics.DrawImage(formImage, 100, 100)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
GetFormImage()
pd.Print()
End Sub

Private Sub GetFormImage()

Dim g As Graphics = Me.CreateGraphics()
Dim s As Size = Me.Size
formImage = New Bitmap(s.Width, s.Height, g)
Dim mg As Graphics = Graphics.FromImage(formImage)
Dim dc1 As IntPtr = g.GetHdc
Dim dc2 As IntPtr = mg.GetHdc
Dim widthDiff As Integer = (Me.Width -
Me.ClientRectangle.Width)
Dim heightDiff As Integer = (Me.Height -
Me.ClientRectangle.Height)
Dim borderSize As Integer = widthDiff \ 2
Dim heightTitleBar As Integer = heightDiff - borderSize
BitBlt(dc2, 0, 0, Me.ClientRectangle.Width + widthDiff, dc1, 0
- borderSize, 0 - heightTitleBar, 13369376)
g.ReleaseHdc(dc1)
mg.ReleaseHdc(dc2)

End Sub
End Class


The error I get is this :-

Argument not specified for parameter 'dwRop' of 'Declare Ansi Function
BitBlt Lib "gdi32.dll" Alias "BitBlt" (hdcDest As System.IntPtr,
nXDest As Integer, nYDest As Integer, nWidth As Integer, nHeight As
Integer, hdcScr As System.IntPtr, nXSrc As Integer, NySrc As Integer,
dwRop As Integer) As Long'.

Thanks in anticipation.

P
 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      8th Mar 2010
Am 08.03.2010 13:05, schrieb Hotrod2000:
> I'am trying to print a windows form with the following code, but keep
> getting this error message (posted below code).
> My form has a few unused labels on in and a print button (Button1)
>
> Any help would be greatly appreiciated :-
>
> Public Class Form1
>
> Private WithEvents pd As Printing.PrintDocument
> Dim formImage As Bitmap
> 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 hdcScr As IntPtr, ByVal nXSrc As Integer, ByVal NySrc As
> Integer, ByVal dwRop As System.Int32) As Long


I didn't read everything because the first step is declaring the
return value As Boolean (not Long).

(dwRop can be declared as UInteger (UInt32), but that doesn't change anything)


--
Armin
 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      8th Mar 2010
Am 08.03.2010 13:05, schrieb Hotrod2000:
> 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 hdcScr As IntPtr, ByVal nXSrc As Integer, ByVal NySrc As
> Integer, ByVal dwRop As System.Int32) As Long




> BitBlt(dc2, 0, 0, Me.ClientRectangle.Width + widthDiff, dc1, 0
> - borderSize, 0 - heightTitleBar, 13369376)




> The error I get is this :-
>
> Argument not specified for parameter 'dwRop' of 'Declare Ansi Function
> BitBlt Lib "gdi32.dll" Alias "BitBlt" (hdcDest As System.IntPtr,
> nXDest As Integer, nYDest As Integer, nWidth As Integer, nHeight As
> Integer, hdcScr As System.IntPtr, nXSrc As Integer, NySrc As Integer,
> dwRop As Integer) As Long'.


I should have read everything...

The message says an argument is missing. Use intellisense while typing.

BitBlt( _
dc2, 0, 0, _
Me.ClientRectangle.Width + widthDiff, <ARGUMENT MISSING HERE>, _
dc1, 0 - borderSize, 0 - heightTitleBar, 13369376 _
)

The missing argument is the height of the rectangle.


In addition, have a look at the methods
- System.Drawing.Graphics.CopyFromScreen
- System.Windows.Forms.Control.DrawToBitmap

--
Armin
 
Reply With Quote
 
Hotrod2000
Guest
Posts: n/a
 
      8th Mar 2010
On 8 Mar, 14:52, Armin Zingler <az.nos...@freenet.de> wrote:
> Am 08.03.2010 13:05, schrieb Hotrod2000:
>
> > * * 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 hdcScr As IntPtr, ByVal nXSrc As Integer, ByVal NySrc As
> > Integer, ByVal dwRop As System.Int32) As Long
> > * * * * BitBlt(dc2, 0, 0, Me.ClientRectangle.Width + widthDiff,dc1, 0
> > - borderSize, 0 - heightTitleBar, 13369376)
> > The error I get is this :-

>
> > Argument not specified for parameter 'dwRop' of 'Declare Ansi Function
> > BitBlt Lib "gdi32.dll" Alias "BitBlt" (hdcDest As System.IntPtr,
> > nXDest As Integer, nYDest As Integer, nWidth As Integer, nHeight As
> > Integer, hdcScr As System.IntPtr, nXSrc As Integer, NySrc As Integer,
> > dwRop As Integer) As Long'.

>
> I should have read everything...
>
> The message says an argument is missing. Use intellisense while typing.
>
> * *BitBlt( _
> * * * dc2, 0, 0, _
> * * * Me.ClientRectangle.Width + widthDiff, <ARGUMENT MISSING HERE>, _
> * * * dc1, 0 - borderSize, 0 - heightTitleBar, 13369376 _
> * *)
>
> The missing argument is the height of the rectangle.
>
> In addition, have a look at the methods
> - System.Drawing.Graphics.CopyFromScreen
> - System.Windows.Forms.Control.DrawToBitmap
>
> --
> Armin



Thanks Armin,

Yep I've put the missing argument in !!! I must check my code writing
more carefully in future !!!

Works a treat with some height code !!!

Thanks again.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Temporary Form with 2 Sub form Update Main Form And its Sub form ? Jeanette Cunningham Microsoft Access Form Coding 0 25th Nov 2009 03:27 AM
Link for sub form on form to sub form in same form billybanter67 Microsoft Access Forms 2 24th May 2008 09:32 AM
Printing cut off when printing on a small form Jonathan Sachs Printers 0 5th Nov 2004 05:11 PM
Printing the currentrecord form a form =?Utf-8?B?Ym1lcnNlcmVhdUB6ZWxsZS5jb20=?= Microsoft Access Macros 2 23rd Aug 2004 01:00 AM
Form Printing Extra Line top of next form Brad Microsoft Access 3 5th Dec 2003 10:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:12 PM.