Just to clarify the "keybd_event" is an API call. I forget to include the
declaration. Richard, Thanks for the total .NET solution! I will try the
SendKeys method, maybe the wait states were required for the API call, but not
with the SendKeys method.
Private Declare Sub keybd_event Lib "user32" (ByVal bVK As Byte, ByVal bScan As
Byte, ByVal dwflags As Long, ByVal dwExtraInfo As Long)
-Todd
|--------+------------------------->
| | Richard Ainsley|
| | <rainsley@p...|
| | ll.net> |
| | |
| | 09/24/2002 |
| | 03:50 PM |
| | Please respond |
| | to |
| | "pro_VB_dotnet"|
| | |
|--------+------------------------->
>--------------------------------------------------------------|
| |
| To: "pro_VB_dotnet" <pro_vb_dotnet@p...> |
| cc: (bcc: Todd Pietrowski/AD-ABR/3M/US) |
| Subject: [pro_vb_dotnet] Re: how to print a window |
| form in VB.NET |
>--------------------------------------------------------------|
Great! I have been pondering this solution for a while. Glad you did it
well. There are a lot of us looking for this logic.
There is a line which has a reference to functinality not part of the .Net
framework that can be substituted with system.forms.sendkeys.send(). Also it
appears that the extra wait states are not necessary. Try substituting the
following code for the Sub PrintScreen() in the submission by Todd (keep
everything else):
Private Sub PrintScreen()
Try
Application.DoEvents() ' keep this to allow drop down menus to rollup
' ' if you want to see drop down menus, comment the doEvents line
''''''''''''''''''''''''''''''''''''''''''''''''''''''
' The following line is not necessary with Pentium II 866 Mhz cpu
' System.Threading.Thread.Sleep(500) ' not necessary???
' The following line references something which is probably not part of the
English version of VS.NET
' keybd_event(44, 1, 0, 0) '1 is current form, 44 is printscreen
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Deploy the sendkeys.send which is appropriate:
' "^{PRTSC}" codes for Alt+prtScrn (dump users screen)
' "^%{PRTSC}" codes for Alt+Ctrl+PrtScrn (dump current form only)
''''''''''''''''''''
' System.Windows.Forms.SendKeys.Send("^{PRTSC}") ' alt {PrtScrn} =>prints
user screen
System.Windows.Forms.SendKeys.Send("^%{PRTSC}") ' ctrl alt {PrintScr} =>
prints current form only
' NOTE: you can also open Wordpad and paste a copy of the screen dump from
the system paste buffer while the printer dialog
' box is being displayed......
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Application.DoEvents() ' allow PrtScrn system function some processing time
Dim myDoc As New PrintDocument()
AddHandler myDoc.PrintPage, AddressOf Me.PrintPageHandler
Dim myPrinter As New PrintDialog()
myPrinter.Document = myDoc
If myPrinter.ShowDialog() = DialogResult.OK Then
myDoc.Print()
End If
Catch exp As Exception
MsgBox(exp.Message)
End Try
End Sub
----- Original Message -----
From: <toddpie@m...>
To: "pro_VB_dotnet" <pro_vb_dotnet@p...>
Cc: <anurag@S...>
Sent: Tuesday, September 24, 2002 5:48 AM
Subject: [pro_vb_dotnet] Re: how to print a window form in VB.NET
>
>
> Try the example below. It prints the current application, not the current
form,
> but it's better than nothing.
>
>
> Imports System.Drawing
> Imports System.Drawing.Printing
>
>
> Private Sub mnuPrintScreen_Click(ByVal sender As System.Object, ByVal e
As
> System.EventArgs) Handles mnuPrintScreen.Click
> PrintScreen()
> End Sub
>
> Private Sub PrintScreen()
> Try
> Application.DoEvents()
> System.Threading.Thread.Sleep(500)
> keybd_event(44, 1, 0, 0) '1 is current form, 44 is printscreen
> Application.DoEvents()
>
> Dim myDoc As New PrintDocument()
> AddHandler myDoc.PrintPage, AddressOf Me.PrintPageHandler
>
> Dim myPrinter As New PrintDialog()
> myPrinter.Document = myDoc
> If myPrinter.ShowDialog() = DialogResult.OK Then
> myDoc.Print()
> End If
> Catch exp As Exception
> MsgBox(exp.Message)
> End Try
> End Sub
>
> Private Sub PrintPageHandler(ByVal sender As Object, ByVal e As
> PrintPageEventArgs)
> Try
> Dim myBitmap As Bitmap
>
> If Clipboard.GetDataObject.GetDataPresent(DataFormats.Bitmap,
True)
> Then
> myBitmap = CType
> (Clipboard.GetDataObject().GetData(DataFormats.Bitmap),
System.Drawing.Bitmap)
>
> Dim myCanvas As Graphics = e.Graphics
> Dim drawString As String
> Dim drawFont As New System.Drawing.Font("Arial", 12)
> Dim drawBrush As New
> System.Drawing.SolidBrush(System.Drawing.Color.Black)
>
> ' Create point for upper-left corner of drawing.
> Dim x As Single = 0
> Dim y As Single = 0
> Dim drawFormat As New System.Drawing.StringFormat()
>
> ' Draw string to screen.
> drawString = "Printed: " + Now.ToShortDateString + " at " +
> Now.ToShortTimeString + _
> " by user " + mobjAppOptions.UserName + " on " +
> System.Windows.Forms.SystemInformation.ComputerName
> e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y,
> drawFormat)
> y += drawFont.GetHeight(e.Graphics)
>
> Dim intScaleWidth As Integer
> Dim intScaleHeight As Integer
>
> intScaleWidth = CInt(IIf(myBitmap.Width >
(e.PageBounds.Width - 50),
> e.PageBounds.Width - 50, myBitmap.Width))
> intScaleHeight = CInt(IIf(myBitmap.Height >
(e.PageBounds.Height -
> 25), e.PageBounds.Height - 25, myBitmap.Height))
>
> myCanvas.DrawImage(myBitmap, x, y, intScaleWidth,
intScaleHeight)
> myBitmap.Dispose()
> Else
> e.Cancel = True
> End If
> Catch exp As Exception
> e.Cancel = True
> End Try
> End Sub
>
>
>
>
> |--------+------------------------->
> | | "Anurag |
> | | Kulshrestha" |
> | | <anurag@s...|
> | | rengg.com> |
> | | |
> | | 08/22/2002 |
> | | 12:04 PM |
> | | Please respond |
> | | to |
> | | "pro_VB_dotnet"|
> | | |
> |--------+------------------------->
> >---------------------------------------------------------|
> | |
> | To: "pro_VB_dotnet" <pro_vb_dotnet@p...>|
> | cc: (bcc: Todd Pietrowski/AD-ABR/3M/US) |
> | Subject: [pro_vb_dotnet] how to print a window |
> | form in VB.NET |
> >---------------------------------------------------------|
>
>
>
>
>
> Hi,
>
> I am not finding how to print a window form (with controls) in VB.NET.
>
> I have developed one application and there is some data on the form in
> some controls and I want to print it in VB.NET.
>
> My Email-id is anurag@S...
>
> Thanks for all kind of help.
>
> Anurag
>
>
>
> ---
> Visual Basic .NET Text Manipulation Handbook
> The .NET Framework brings a variety of string manipulation features
> to the VB language, and some of these, namely regular expressions
> and the StringBuilder class, are something VB 6 developers may not
> have seen before. This book teaches you how to manipulate text using
> these string matching, manipulation, and replacement classes. Issues
> such as Localization and data conversion will also be investigated.
> http://www.wrox.com/ACON11.asp?ISBN=1861007302
>
>
>
>
> ---
> Visual Basic .NET Text Manipulation Handbook
> The .NET Framework brings a variety of string manipulation features
> to the VB language, and some of these, namely regular expressions
> and the StringBuilder class, are something VB 6 developers may not
> have seen before. This book teaches you how to manipulate text using
> these string matching, manipulation, and replacement classes. Issues
> such as Localization and data conversion will also be investigated.
> http://www.wrox.com/ACON11.asp?ISBN=1861007302
---
Visual Basic .NET Text Manipulation Handbook
The .NET Framework brings a variety of string manipulation features
to the VB language, and some of these, namely regular expressions
and the StringBuilder class, are something VB 6 developers may not
have seen before. This book teaches you how to manipulate text using
these string matching, manipulation, and replacement classes. Issues
such as Localization and data conversion will also be investigated.
http://www.wrox.com/ACON11.asp?ISBN=1861007302