473,396 Members | 1,860 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,396 software developers and data experts.

Printing from classes and modules

Hi there

Ive got a class which i use for alot of data storage in my program and id like to add a print routine to this class so that i can print out a formatted version of all the data. I just cant seem to work out how to create a document in the class and then link the preview and print dialogs to it. Does anyone have any tips or know of tutorials which show how to do this with out placing controls on a form. Hope someone can help out

Regard

James Procto

http://www.ebmis.co.u
Nov 20 '05 #1
4 1096
Hi,

I would add a printdocument variable to print from a class

Dim WithEvents m_pdMyDoc As System.Drawing.Printing.PrintDocument

Private Sub m_pdMyDoc_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles m_pdMyDoc.PrintPage

Dim fnt As New Font(FontFamily.GenericSansSerif, FontStyle.Regular)

e.Graphics.DrawString("Test", fnt, Brushes.Black, 0, 0)

End Sub

Public Sub PrintOut()

m_pdMyDoc.Print()

End Sub

Ken

----------------------------

"James Proctor" <ja**********@ebmis.co.uk> wrote in message
news:B7**********************************@microsof t.com...
Hi there,

Ive got a class which i use for alot of data storage in my program and id like to add a print routine to this class so that i can print out a
formatted version of all the data. I just cant seem to work out how to
create a document in the class and then link the preview and print dialogs
to it. Does anyone have any tips or know of tutorials which show how to do
this with out placing controls on a form. Hope someone can help out.
Regards
James Proctor

http://www.ebmis.co.uk

Nov 20 '05 #2
* "=?Utf-8?B?SmFtZXMgUHJvY3Rvcg==?=" <ja**********@ebmis.co.uk> scripsit:
Ive got a class which i use for alot of data storage in my program and
id like to add a print routine to this class so that i can print out a
formatted version of all the data. I just cant seem to work out how to
create a document in the class and then link the preview and print
dialogs to it. Does anyone have any tips or know of tutorials which show
how to do this with out placing controls on a form. Hope someone can
help out.


See:

<http://www.mvps.org/dotnet/dotnet/samples/printing/downloads/PrintFramework.zip>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Ok ive got this code now, but when i call the print preview sub it shows the print preview dialog but says there are no pages in this document. Whys this? Am i doing something stupid that im missing out on. Hope you can help. Thanks for your help so far.

JP

Dim WithEvents PrintDocument1 As Drawing.Printing.PrintDocument

Public Sub PrintPreview()
Dim PrintDocPreview As New PrintPreviewDialog
With PrintDocPreview
.Document = Me.PrintDocument1
.ShowDialog()
End With
End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim Font As New Font("Arial", 24, FontStyle.Bold)
Dim XPos, YPos As Single
Dim Lineheight As Single = 50
XPos = e.MarginBounds.Left
YPos = e.MarginBounds.Top
e.Graphics.DrawString("Kit ID:", Font, Brushes.Black, XPos, YPos)
YPos = 100
e.Graphics.DrawString(Trim(Me.ID), Font, Brushes.Black, XPos, YPos)
End Sub
Nov 20 '05 #4
Hi,

Dim WithEvents PrintDocument1 As New Drawing.Printing.PrintDocument

Ken
---------------------
"James Proctor" <ja**********@ebmis.co.uk> wrote in message
news:97**********************************@microsof t.com...
Ok ive got this code now, but when i call the print preview sub it shows the print preview dialog but says there are no pages in this document. Whys
this? Am i doing something stupid that im missing out on. Hope you can help.
Thanks for your help so far.
JP
Public Sub PrintPreview()
Dim PrintDocPreview As New PrintPreviewDialog
With PrintDocPreview
.Document = Me.PrintDocument1
.ShowDialog()
End With
End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e

As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage Dim Font As New Font("Arial", 24, FontStyle.Bold)
Dim XPos, YPos As Single
Dim Lineheight As Single = 50
XPos = e.MarginBounds.Left
YPos = e.MarginBounds.Top
e.Graphics.DrawString("Kit ID:", Font, Brushes.Black, XPos, YPos)
YPos = 100
e.Graphics.DrawString(Trim(Me.ID), Font, Brushes.Black, XPos, YPos) End Sub

Nov 20 '05 #5

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

Similar topics

8
by: Rob Snyder | last post by:
Greetings - I have a situation where I need to be able to have a Python function that will take all the modules in a given directory and find all the classes defined in these modules by name....
7
by: Dennis C. Drumm | last post by:
I was wondering if someone could suggest were/how I could get started with setting up printing of a collection of text that includes tables from a grid and other supporting information about the...
4
by: Tom | last post by:
Does anyone know if the following kb article applies to the .NET framework 1.1? http://support.microsoft.com/?kbid=324565 It states: 'Any service that is designed to print must directly use...
11
by: John Salerno | last post by:
From my brief experience with C#, I learned that it was pretty standard practice to put each class in a separate file. I assume this is a benefit of a compiled language that the files can then be...
5
by: Alex | last post by:
Hi, this is my first mail to the list so please correct me if Ive done anything wrong. What Im trying to figure out is a good way to organise my code. One class per .py file is a system I like,...
1
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
Any tips on how to print the data in a datagridview control?
173
by: Zytan | last post by:
I've read the docs on this, but one thing was left unclear. It seems as though a Module does not have to be fully qualified. Is this the case? I have source that apparently shows this. Are...
12
by: Janaka Perera | last post by:
Hi All, We have done a object oriented design for a system which will create a class multiply inherited by around 1000 small and medium sized classes. I would be greatful if you can help me...
1
by: giddy | last post by:
hi, I'm not very familiar with printing , but i've read about the printing classes in .NET. Now , I know my print code has to go to the PrintPage event. but i have a full apllication with a ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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,...

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.