473,503 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing/Print Preview Problem

I want to Print a txt file with this code :

class Printing

{

PrintDocument prndoc = new PrintDocument();

PrintPreviewDialog ppd = new PrintPreviewDialog();

PrintDialog prn = new PrintDialog();

public Printing()

{

prndoc.PrintPage += new PrintPageEventHandler(PrintPage);

ppd.Document = prndoc;

prn.Document = prndoc;
prn.AllowSomePages = true;

prn.PrinterSettings.FromPage = 1;

prn.PrinterSettings.ToPage = prn.PrinterSettings.MaximumPage;

}

public void PrintPage(object obj, PrintPageEventArgs e)

{
string strPrintText;

StreamReader strread = new StreamReader("C:\\Haftungsausschluss.txt");

StringFormat strF = new StringFormat();

strPrintText = strread.ToString();
Graphics grfx = e.Graphics;

Font font = new Font("Arial",300);

float cyFont = font.GetHeight(grfx);

RectangleF rectfFull, rectfText;
rectfFull = new RectangleF(

e.MarginBounds.Left - (e.PageBounds.Width - grfx.VisibleClipBounds.Width)
/2,

e.MarginBounds.Top - (e.PageBounds.Height - grfx.VisibleClipBounds.Height)
/2,

e.MarginBounds.Width , e.MarginBounds.Height);

rectfText = RectangleF.Inflate(rectfFull, 0,-2 * cyFont);
int iDisplayLines = (int) Math.Floor(rectfText.Height / cyFont);

rectfText.Height = iDisplayLines * cyFont;

grfx.DrawString(strPrintText,font,Brushes.Black,re ctfText,strF);
}

But how I start the Print Preview / Printing ??


Nov 15 '05 #1
2 2757

"Pkant" <pk***@isc-greiner.de> wrote in message
news:uy*************@TK2MSFTNGP10.phx.gbl...
I want to Print a txt file with this code :

class Printing

{

PrintDocument prndoc = new PrintDocument();

PrintPreviewDialog ppd = new PrintPreviewDialog();

PrintDialog prn = new PrintDialog();
But how I start the Print Preview / Printing ??


ppd.ShowDialog();
prn.ShowDialog();

// Luc K

Nov 15 '05 #2
Hi,

There's also a PrintController class (it has several species). I beleive
this is the class that controls the printing process.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Pkant" <pk***@isc-greiner.de> wrote in message
news:uy*************@TK2MSFTNGP10.phx.gbl...
I want to Print a txt file with this code :

class Printing

{

PrintDocument prndoc = new PrintDocument();

PrintPreviewDialog ppd = new PrintPreviewDialog();

PrintDialog prn = new PrintDialog();

public Printing()

{

prndoc.PrintPage += new PrintPageEventHandler(PrintPage);

ppd.Document = prndoc;

prn.Document = prndoc;
prn.AllowSomePages = true;

prn.PrinterSettings.FromPage = 1;

prn.PrinterSettings.ToPage = prn.PrinterSettings.MaximumPage;

}

public void PrintPage(object obj, PrintPageEventArgs e)

{
string strPrintText;

StreamReader strread = new StreamReader("C:\\Haftungsausschluss.txt");

StringFormat strF = new StringFormat();

strPrintText = strread.ToString();
Graphics grfx = e.Graphics;

Font font = new Font("Arial",300);

float cyFont = font.GetHeight(grfx);

RectangleF rectfFull, rectfText;
rectfFull = new RectangleF(

e.MarginBounds.Left - (e.PageBounds.Width - grfx.VisibleClipBounds.Width)
/2,

e.MarginBounds.Top - (e.PageBounds.Height - grfx.VisibleClipBounds.Height)
/2,

e.MarginBounds.Width , e.MarginBounds.Height);

rectfText = RectangleF.Inflate(rectfFull, 0,-2 * cyFont);
int iDisplayLines = (int) Math.Floor(rectfText.Height / cyFont);

rectfText.Height = iDisplayLines * cyFont;

grfx.DrawString(strPrintText,font,Brushes.Black,re ctfText,strF);
}

But how I start the Print Preview / Printing ??



Nov 15 '05 #3

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

Similar topics

3
4765
by: Fabio Pliger | last post by:
Hi! I'm using wxPython to handle my application gui.. So, I have a notebook widget and i have to print the object inside it's tab ... Maybe doing a preview before printing... I know that wx has...
8
3236
by: Rob McLennan - ZETLAND | last post by:
Hi, I have set up an external stylesheet, named "print.css", to format the style of all pages printed from my company's website. I've been previewing my changes to the stylesheet by doing...
8
9585
by: Tinus | last post by:
Hello all, Because you have been so helpfull the last couple of times, I thought after testing and wasting more than 20 pages (and google-ling for 3 days :-( ). I would ask you again for your...
4
1889
by: Al Jones | last post by:
Well, hopefully that title get someones attention. In this old gwbasic program I've converted I *have* sucessuflly converted it to print to a file and the output is acceptable. From there I have...
1
5682
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
2
288
by: =?Utf-8?B?UGxheWE=?= | last post by:
When I display my print preview dialog all text and data displays as expected but when I print it some of the text isn't printing. I can't figure out why it displays fine in teh print preview but...
8
5871
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
2
9930
by: Brad Pears | last post by:
I have a vb.net 2005 application and am using the print preview screen. This screen has a printer icon on it that the user can use to print the document currently being viewed. It uses the default...
2
8303
by: deepakfordotnet | last post by:
Hi, First of all let me confess that I could not get the solution to the same problem from an earlier post Printing :by Mr.Richard MSL (dated September 24th 2006) working. (Replied by Mr.Walter...
2
7613
by: JF | last post by:
Hello, I have a problem with a print.css. When trying to print or using the print preview in Firefox only a blank page is shown. At http://80.190.188.58/test/test.html you can find a test-page...
0
7202
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
7086
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...
0
7280
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
7332
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
5578
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,...
1
5014
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...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1512
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 ...
0
382
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...

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.