473,563 Members | 2,662 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2435
Hello,

"Igor" <iv***********@ dectechsolution s.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.Componen tModel.Containe r
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.
InitializeCompo nent()
End Sub

' The Click event is raised when the user clicks the
Print button.
Private Sub printButton_Cli ck(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.C lose()
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(By Val sender As Object,
ByVal ev As PrintPageEventA rgs)
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.GetHe ight(ev.Graphic s)

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

ev.Graphics.Dra wString(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 InitializeCompo nent()
Me.components = New
System.Componen tModel.Containe r
Me.printButton = New System.Windows. Forms.Button

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

printButton.Ima geAlign =
System.Drawing. ContentAlignmen t.MiddleLeft
printButton.Loc ation = New System.Drawing. Point
(32, 110)
printButton.Fla tStyle =
System.Windows. Forms.FlatStyle .Flat
printButton.Tab Index = 0
printButton.Tex t = "Print the file."
printButton.Siz e = New System.Drawing. Size(136,
40)
AddHandler printButton.Cli ck, AddressOf
printButton_Cli ck

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.a u> 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
1906
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 InvalidPrinterException exception saying "No Printers Installed". Is this a bug or behavior by design? Is there anything I can do about this or should I just...
3
5300
by: Palli Olafs | last post by:
Hi Is it possible to save the PrintDocument as file without using a printer?
1
2406
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). Seeing how everything in ..NET prints to a PrintDocument object, I was wondering how I can retrieve the hDC of the PrintDocument? Or am I looking...
0
1401
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 I wanted to do something like the above except that I wanted mPrinternameSaved to be an additional set of data identical to that stored
3
6278
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 computer has drivers installed for this printer, and this printer is shared for the network. Question 1:
2
28453
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 properties of the PageSettings in the Print handler are reporting values that indicate 100 dpi, for example it reports PaperSize as 850, 1100 (8.5" x...
2
6614
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 values). I noticed that we can specified the PrintRange, FromPage and ToPage properties of the PrintDocument.PrintSettings object, but, as said in...
1
11168
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 paint the next page on top of the original page. In a sample data case where the source is long enough to fill three pages, I end up with four calls to...
16
4509
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 screen, when I open a file, the entire contents of the file is in fact being shown...so why can't I print it later? All of this code I am getting from...
0
7658
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7631
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7943
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6238
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3615
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2077
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
912
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.