Jump to content
Xtreme .Net Talk

Recommended Posts

  • 4 weeks later...
Posted (edited)

Copy to bmp file them print the bmp...

 

If you can't do it directly then why not indirectly?

 

try copying the entire form as a .bmp to a file and then print that file...

 

I have only a vague idea on how to do that and will explore it, but if anyone out there thinks that you can do it please do as I have a great deal on my plate to get done this month....

 

 

Thanx...

 

This might help:

 

NOTE: Copy the following ( with out the quotes ) to your IE address bar and press <Enter>

 

"ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemDrawingPrintingPrintDocumentClassPrintTopic.htm"

 

 

 

Question: Why doesn't the URL code below work??

http://ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemDrawingPrintingPrintDocumentClassPrintTopic.htm

Edited by UCM

UCM

>-)

  • 5 months later...
Posted

This code isn't mine, I found it on the web. It seems to do what you want. I've been tinkering with it for a project.

 

 

Option Explicit On

Option Strict On

'**********************************************************************************

' PrintForm Class

'

' Purpose: Print active window

'

' Dependencies:

'

' Author: Øyvind Rustan - Compositae, 27.05.2002

' http://www.compositae.no

' Revision:

'

'**********************************************************************************

 

Imports System.Windows

Imports System.Drawing

 

Public Class PrintForm

'------------------------------------------------------------------------------

' New

' Constructor

'------------------------------------------------------------------------------

Public Sub New()

End Sub

 

'------------------------------------------------------------------------------

' Print

' Print active window (form)

'------------------------------------------------------------------------------

Public Sub Print()

Try

'-- Keys Alt+PrintScreen copies active window to clipboard

Forms.SendKeys.SendWait("%{PRTSC}")

'-- Create print document and printing handler

Dim pd As New Printing.PrintDocument()

AddHandler pd.PrintPage, AddressOf pd_PrintPage

'-- Setup document

pd.DocumentName = "PrintScreen"

With pd.DefaultPageSettings

.Landscape = False

'-- Reduce margins to accomodate larger pictures

.Margins.Left -= .Margins.Left \ 3

.Margins.Top -= .Margins.Top \ 3

.Margins.Right -= .Margins.Right \ 3

.Margins.Bottom -= .Margins.Bottom \ 3

End With

'-- Print document

pd.Print()

Catch ex As Exception

Throw ex

End Try

End Sub

 

'------------------------------------------------------------------------------

' pd_PrintPage

' PrintPage handler

'------------------------------------------------------------------------------

Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As Printing.PrintPageEventArgs)

Try

'-- Get PrintScreen bitmap from clipboard

Dim iData As IDataObject = Clipboard.GetDataObject()

If iData.GetDataPresent(DataFormats.Bitmap) Then

Dim bm As Bitmap = CType(iData.GetData(DataFormats.Bitmap), Bitmap)

'-- Set size of destination rectangle (printer)

Dim rDest As New RectangleF(ev.MarginBounds.Left, ev.MarginBounds.Top, 0, 0)

If bm.Width < ev.MarginBounds.Width Then

'-- Set to bitmap size if bitmap is smaller than paper

rDest.Width = bm.Width

rDest.Height = bm.Height

Else

'-- Set to paper size if bitmap is larger than paper

'-- Scale height to retain proportions

rDest.Width = ev.MarginBounds.Width

rDest.Height = CType(rDest.Width * (bm.Height / bm.Width), Single)

End If

'-- Draw bitmap

ev.Graphics.DrawImage(bm, rDest, bm.GetBounds(GraphicsUnit.Pixel), GraphicsUnit.Pixel)

'-- Draw timestamp

Dim printFont As Font = New Font("Arial", 10, FontStyle.Regular)

ev.Graphics.DrawString(Now.ToString, printFont, Brushes.Black, rDest.Left, rDest.Top + rDest.Height + printFont.GetHeight(ev.Graphics))

Else

'-- No bitmap, cancel printing

ev.Cancel = True

End If

Catch ex As Exception

'-- Cancel printing

ev.Cancel = True

Throw ex

Finally

'-- Print only on page

ev.HasMorePages = False

End Try

End Sub

End Class

  • 1 month later...
Posted

Okay,

 

Here's three ways to do it:

 

1) If you the form is on the screen and is not cut off in any way (ie: no other window is above the form by any means, and the form is not off the screen), and all the controls on the screen are things like labels and buttons, not any of YOUR own classes:

 

http://www.c-sharpcorner.com/Code/2003/March/FormPrinting.asp

 

2) Same as one but you have some of your own classes or things not defined by ControlPaint.draw.. (groupbox is NOT)

 

http://www.c-sharpcorner.com/Graphics/ScreenCaptFormMG.asp

 

3) You are in the same boat as me and have your own classes and things like the print dialog or the form being too big on the screen (it might use scroll bars, might be off the monitor, etc) getting in the way and taking place of the actual "image".

 

http://www.xtremedotnettalk.com/t74549/s.html

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...