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. 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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
by: Palli Olafs |
last post by:
Hi
Is it possible to save the PrintDocument as file without using a printer?
|
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). ...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |