473,405 Members | 2,300 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,405 software developers and data experts.

PrintDocument Exception

Hi, I have a problem when I attempt to utilize the
PrintDocument component. I basically copy word for word
the code provided under the PrintDocument overview help,
but I keep getting the same exception. The message
states: "The data area passed to a system call is too
small". If anyone has an idea about what this means or
how to fix it, please let me know. THanks.
Nov 20 '05 #1
3 2427
Hello,

"Igor" <iv***********@dectechsolutions.com> schrieb:
Hi, I have a problem when I attempt to utilize the
PrintDocument component. I basically copy word for word
the code provided under the PrintDocument overview help,
but I keep getting the same exception. The message
states: "The data area passed to a system call is too
small". If anyone has an idea about what this means or
how to fix it, please let me know. THanks.


Post some code.

Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #2
Here is the entire code

Imports System.IO
Imports System.Drawing
Imports System.Drawing.Printing
Public Class PrintingExample
Inherits System.Windows.Forms.Form
Private components As System.ComponentModel.Container
Private printButton As System.Windows.Forms.Button
Private printFont As Font
Private streamToPrint As StreamReader

Public Sub New()
' The Windows Forms Designer requires the
following call.
InitializeComponent()
End Sub

' The Click event is raised when the user clicks the
Print button.
Private Sub printButton_Click(ByVal sender As Object,
ByVal e As EventArgs)
Try
streamToPrint = New StreamReader
("C:\trash.txt")
Try
printFont = New Font("Arial", 10)
Dim pd As New PrintDocument
AddHandler pd.PrintPage, AddressOf
Me.pd_PrintPage
pd.Print()
Finally
streamToPrint.Close()
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

' The PrintPage event is raised for each page to be
printed.
Private Sub pd_PrintPage(ByVal sender As Object,
ByVal ev As PrintPageEventArgs)
Dim linesPerPage As Single = 0
Dim yPos As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
Dim line As String = Nothing

' Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics)

' Print each line of the file.
While count < linesPerPage
line = streamToPrint.ReadLine()
If line Is Nothing Then
Exit While
End If
yPos = topMargin + count * printFont.GetHeight
(ev.Graphics)

ev.Graphics.DrawString(line, printFont,
Brushes.Black, leftMargin, yPos, New StringFormat)

count += 1
End While

' If more lines exist, print another page.
If Not (line Is Nothing) Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
End Sub
' The Windows Forms Designer requires the following
procedure.
Private Sub InitializeComponent()
Me.components = New
System.ComponentModel.Container
Me.printButton = New System.Windows.Forms.Button

Me.AutoScaleBaseSize = New System.Drawing.Size(5,
13)
Me.ClientSize = New System.Drawing.Size(504, 381)
Me.Text = "Print Example"

printButton.ImageAlign =
System.Drawing.ContentAlignment.MiddleLeft
printButton.Location = New System.Drawing.Point
(32, 110)
printButton.FlatStyle =
System.Windows.Forms.FlatStyle.Flat
printButton.TabIndex = 0
printButton.Text = "Print the file."
printButton.Size = New System.Drawing.Size(136,
40)
AddHandler printButton.Click, AddressOf
printButton_Click

Me.Controls.Add(printButton)
End Sub

' This is the main entry point for the
application.
Public Shared Sub Main()
Application.Run(New PrintingExample)
End Sub

End Class
Nov 20 '05 #3
Hello,

"Igor" <iv***********@optushome.com.au> schrieb:
Here is the entire code


The code works on my Windows XP machine running .NET 1.0.

Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jeffry van de Vuurst | last post by:
Hi, I have a PrintDocument that I preview in a PrintPreviewControl. Now I run the app on a pc without any printers installed and when I want to preview the PrintDocument I get an...
3
by: Palli Olafs | last post by:
Hi Is it possible to save the PrintDocument as file without using a printer?
1
by: Frank Rizzo | last post by:
Hello, I have an OCX control on my WinForm (don't ask, i have to use it) and it generally works well. One of the methods of the OCX prints to an hDC (device context handle for history buffs). ...
0
by: active | last post by:
Dim mPD As PrintDocument Dim mPrinternameSaved As PrintDocument Public WriteOnly Property PrintDocument() As PrintDocument Set(ByVal value As PrintDocument) mPD = value mPrinternameSaved = mPD...
3
by: Mika M | last post by:
Hi all! I have made an application for printing simple barcode labels using PrintDocument object, and it's working fine. Barcode printer that I use is attached to the computer, and this...
2
by: Steve | last post by:
I'm trying real hard to set the printer resolution for a PrintDocument. It appears that the printer is already set to 300 x 300 dpi, which is JUST what I want. But the Margins and PrintableArea...
2
by: bp | last post by:
Hi, I try to use my own PreviewDialog with a PrinPreviewControl, to preview a document of type MyPrintDocument, and I want to implement the PrintRange functionnality (print some pages between 2...
1
by: kig25 | last post by:
Hello, When using the VB.NET PrintDocument class, I seem to be encountering an issue where the sub pd_PrintPage handles PrintDocument.PrintPage (upon continuing if HasMorePages = true) will...
16
by: raylopez99 | last post by:
I am running out of printing paper trying to debug this...it has to be trivial, but I cannot figure it out--can you? Why am I not printing text, but just the initial string "howdy"? On the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.