Simple printing with VB.NET? 
Author Message
 Simple printing with VB.NET?

I need to print some text with a network printer from my VB.NET
application. All the Printer methods from VB6 are gone and instead we
have this incredibly complex PrintDocument control.

So far I have put a PrintDialog control and PrintDocument Control on the
form. The user can select which printer to use, etc with the
PrintDialog. One of the properties is the PrintDocument object. After
that, I'm lost.

Examples I've seen so far are extremely complicated. Can someone please
direct me to a tutorial or example of using this control to do some
simple formatted text?

Or maybe a snippet of code here? Just to print "Hello World"?

Thanks.



Mon, 17 Oct 2005 22:28:18 GMT  
 Simple printing with VB.NET?
Hello,


Quote:
> So far I have put a PrintDialog control and PrintDocument
> Control on the form. The user can select which printer to
> use, etc with the PrintDialog. One of the properties is the
> PrintDocument object. After that, I'm lost.

> Examples I've seen so far are extremely complicated. Can
> someone please direct me to a tutorial or example of using this
> control to do some simple formatted text?

http://www.vbsource.net.ms/dotnet/samples/printing/
-> sample "PrintFramework"

Regards,
Herfried K. Wagner



Mon, 17 Oct 2005 23:16:00 GMT  
 Simple printing with VB.NET?

Quote:

> I need to print some text with a network printer from my VB.NET
> application. All the Printer methods from VB6 are gone and instead we
> have this incredibly complex PrintDocument control.

> So far I have put a PrintDialog control and PrintDocument Control on the
> form. The user can select which printer to use, etc with the
> PrintDialog. One of the properties is the PrintDocument object. After
> that, I'm lost.

> Examples I've seen so far are extremely complicated. Can someone please
> direct me to a tutorial or example of using this control to do some
> simple formatted text?

> Or maybe a snippet of code here? Just to print "Hello World"?

> Thanks.

Hi,

try this:

    Private Sub print()
        Dim loPrintProcess As New System.Diagnostics.Process()
        Dim loStartInfo As New System.Diagnostics.ProcessStartInfo()

        '# File to print
        loStartInfo.FileName = "c:\adb.txt"

        '# What to do with the file
        loStartInfo.Verb = "print"

        '# Let's print
        loPrintProcess = Process.Start(loStartInfo)
    End Sub

and look into the docs for further information on Process.

Bye

  Brodehead



Tue, 18 Oct 2005 03:44:42 GMT  
 Simple printing with VB.NET?
Ummm... thanks, but what language is that?

<sigh>

Quote:

> Hello,


> > So far I have put a PrintDialog control and PrintDocument
> > Control on the form. The user can select which printer to
> > use, etc with the PrintDialog. One of the properties is the
> > PrintDocument object. After that, I'm lost.

> > Examples I've seen so far are extremely complicated. Can
> > someone please direct me to a tutorial or example of using this
> > control to do some simple formatted text?

> http://www.vbsource.net.ms/dotnet/samples/printing/
> -> sample "PrintFramework"

> Regards,
> Herfried K. Wagner



Wed, 19 Oct 2005 03:37:07 GMT  
 Simple printing with VB.NET?
Hello Dave,


Quote:
> Ummm... thanks, but what language is that?

The code: VB .NET
The text: German (don't care about the text)

;-)

Regards,
Herfried K. Wagner



Wed, 19 Oct 2005 03:53:28 GMT  
 Simple printing with VB.NET?
Here's some code from my book which might help. It shows both drawing
individual objects as well as "capturing" the entire form.

Option Strict On

Public Class printingSample
 Inherits System.Windows.Forms.Form

' Windows Form Designer generated code

#Region "Variables"
 Private printWholeForm As Boolean = False
 Private memImage As Bitmap
#End Region

#Region "Base Events"
 Private Sub print_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
  Handles printGraphic.Click, printForm.Click

  Dim buttonID As Button = CType(sender, Button)

  If buttonID.Name = "printForm" Then
   printWholeForm = True
   Call BuildFormImage()
  End If
  PrintDialog1.Document = PrintDocument1
  If PrintDialog1.ShowDialog = DialogResult.OK Then
   PrintDocument1.Print()
  End If
 End Sub

 Private Sub printPreview_Click(ByVal sender As System.Object, ByVal e As _
  System.EventArgs) Handles printPreviewGraphics.Click,
printPreviewForm.Click

  Dim buttonID As Button = CType(sender, Button)
  Dim PrintPreviewID As New PrintPreviewDialog()

  PrintPreviewID.Document = PrintDocument1
  If buttonID.Name = "printPreviewForm" Then
   printWholeForm = True
   Call BuildFormImage()
  End If
  If PrintPreviewID.ShowDialog = DialogResult.OK Then
   PrintDocument1.Print()
  End If
 End Sub

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

  Dim formGraphics As Graphics = e.Graphics

  If printWholeForm = False Then
   ' Build each part of the picture
   With formGraphics
    .DrawString(Label1.Text, Label1.Font, New SolidBrush(Label1.ForeColor),
50, 50)
    .DrawImage(PictureBox1.Image, 100, 100)
    .Dispose()
   End With
  Else
   formGraphics.DrawImage(memImage, 0, 0)
   memImage.Dispose()
   formGraphics.Dispose()
   printWholeForm = False
  End If
  e.HasMorePages = False
 End Sub
#End Region

#Region "Implementation Methods"
 Private Sub BuildFormImage()

  ' Thanks to Lion Shi, MCSE, MCSD, Microsoft Support Engineer, for the
newsgroup post
  ' that showed how to do this

  Dim graphicID As Graphics = Me.CreateGraphics
  Dim sizeID As Size = Me.Size
  Const SRCCOPY As Integer = &HCC0020

  memImage = New Bitmap(sizeID.Width, sizeID.Height, graphicID)
  Dim memGraphic As Graphics = graphicID.FromImage(memImage)
  Dim deviceContext1 As IntPtr = graphicID.GetHdc
  Dim deviceContext2 As IntPtr = memGraphic.GetHdc

  BitBlt(deviceContext2, 0, 0, Me.ClientRectangle.Width,
Me.ClientRectangle.Height, _
   deviceContext1, 0, 0, SRCCOPY)
  graphicID.ReleaseHdc(deviceContext1)
  memGraphic.ReleaseHdc(deviceContext2)
 End Sub

 Private Declare Auto Function BitBlt Lib "gdi32.dll" (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 Boolean
#End Region
End Class

Hope this is helpful.

--
Jeff Rhodes
Author of "VBTrain.Net: Creating Computer and Web Based Training with Visual
Basic .NET"
www.vbtrain.net
Check out our Windows Forms and ASP.NET Controls


Quote:
> I need to print some text with a network printer from my VB.NET
> application. All the Printer methods from VB6 are gone and instead we
> have this incredibly complex PrintDocument control.

> So far I have put a PrintDialog control and PrintDocument Control on the
> form. The user can select which printer to use, etc with the
> PrintDialog. One of the properties is the PrintDocument object. After
> that, I'm lost.

> Examples I've seen so far are extremely complicated. Can someone please
> direct me to a tutorial or example of using this control to do some
> simple formatted text?

> Or maybe a snippet of code here? Just to print "Hello World"?

> Thanks.



Wed, 19 Oct 2005 06:09:11 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Simple Print in VB.NET

2. Can't figure out a simple update procedure in vb.net

3. VB.Net Newbie has Simple Question

4. a Simple Horizontal Line in VB.net

5. use a simple dll that was written in VC++ 6 within VB.net

6. Simple add record form with VB.NET and AccessDB

7. Simple Date Control in VB .Net

8. Simple vb.net winforms datagrid usage

9. VB.NET and simple file operations

10. Error while compiling simple form from command line in VB.net

11. Simple VB.net Question?

12. Write Simple Text To A File In VB.NET

 

 
Powered by phpBB® Forum Software