473,785 Members | 2,575 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() ;

PrintPreviewDia log ppd = new PrintPreviewDia log();

PrintDialog prn = new PrintDialog();

public Printing()

{

prndoc.PrintPag e += new PrintPageEventH andler(PrintPag e);

ppd.Document = prndoc;

prn.Document = prndoc;
prn.AllowSomePa ges = true;

prn.PrinterSett ings.FromPage = 1;

prn.PrinterSett ings.ToPage = prn.PrinterSett ings.MaximumPag e;

}

public void PrintPage(objec t obj, PrintPageEventA rgs e)

{
string strPrintText;

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

StringFormat strF = new StringFormat();

strPrintText = strread.ToStrin g();
Graphics grfx = e.Graphics;

Font font = new Font("Arial",30 0);

float cyFont = font.GetHeight( grfx);

RectangleF rectfFull, rectfText;
rectfFull = new RectangleF(

e.MarginBounds. Left - (e.PageBounds.W idth - grfx.VisibleCli pBounds.Width)
/2,

e.MarginBounds. Top - (e.PageBounds.H eight - grfx.VisibleCli pBounds.Height)
/2,

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

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

rectfText.Heigh t = iDisplayLines * cyFont;

grfx.DrawString (strPrintText,f ont,Brushes.Bla ck,rectfText,st rF);
}

But how I start the Print Preview / Printing ??


Nov 15 '05 #1
2 2770

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

class Printing

{

PrintDocument prndoc = new PrintDocument() ;

PrintPreviewDia log ppd = new PrintPreviewDia log();

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******** *****@TK2MSFTNG P10.phx.gbl...
I want to Print a txt file with this code :

class Printing

{

PrintDocument prndoc = new PrintDocument() ;

PrintPreviewDia log ppd = new PrintPreviewDia log();

PrintDialog prn = new PrintDialog();

public Printing()

{

prndoc.PrintPag e += new PrintPageEventH andler(PrintPag e);

ppd.Document = prndoc;

prn.Document = prndoc;
prn.AllowSomePa ges = true;

prn.PrinterSett ings.FromPage = 1;

prn.PrinterSett ings.ToPage = prn.PrinterSett ings.MaximumPag e;

}

public void PrintPage(objec t obj, PrintPageEventA rgs e)

{
string strPrintText;

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

StringFormat strF = new StringFormat();

strPrintText = strread.ToStrin g();
Graphics grfx = e.Graphics;

Font font = new Font("Arial",30 0);

float cyFont = font.GetHeight( grfx);

RectangleF rectfFull, rectfText;
rectfFull = new RectangleF(

e.MarginBounds. Left - (e.PageBounds.W idth - grfx.VisibleCli pBounds.Width)
/2,

e.MarginBounds. Top - (e.PageBounds.H eight - grfx.VisibleCli pBounds.Height)
/2,

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

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

rectfText.Heigh t = iDisplayLines * cyFont;

grfx.DrawString (strPrintText,f ont,Brushes.Bla ck,rectfText,st rF);
}

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
4779
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 many objects to handle printing.. i've tryied to use them, but i wasn't able to... Any hint? By now, i solved the problem saving a screenshot if the screen in an image(bmp) and then sending it to printer... (a print preview would be cool...) tnx...
8
3252
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 File\Print Preview in IE6 and noticed that occasionally the leftmost button of the javascript menu (CoolMenus Version 3.02) on our website is printed. (I have wrapped the javascript that generates this menu in a DIV so that it is concealed from...
8
9630
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 help. The problem is this: If I print a rectangle which begins at (0,0) and the margins are also set to 0 (l:0, t:0, r:0, b:0) then it prints fine (ok, not quite because 0,0 is inside the none printable area but I corrected for that by checking...
4
1897
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 printPreview and (what is it) PrinDocument working. All of the references I've found (to include several books) show that method of printing ... my question - is it not possible to print the document 'on the fly' to allow proper paging, page...
1
5721
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 of a Microsoft book, "Visual Basic,Net Step by Step" in Chapter 18. All but the bottom two subroutines will open a text file, and then allow me to use the above controls, example 1. The bottom two subroutines will print a graphic file, example...
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 some text wont print. Can anyone help? Thanks in advance.
8
5912
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 clients (Internet Explorer). My flash content was originally brought in via the “flash satay” method, but I have since used some server-side magic do deliver one <objecttag
2
9976
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 printer settings to print. I wanted the print preview to appear the same for all users (i.e. a default page size of 8.5x14 (legal) and portrait mode). Many users have different printers as their default (plotters etc..) and I found that various...
2
8343
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 Wang - September 27th 2006) My problem is to Print a text from a RichTextBox with all options like - AllowMultiplePages enabled plus PrintPreview and PageSetup. I tried 2 algorithms - 1 posted in Microsoft and 1 posted in this forum. ...
2
7656
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 with the problem (please ignore some missing images and additonal, unrelevant css-files for screen-rendering). Printing works as expected in Opera 9.27, IE 6, IE 7 and Safari.
0
9645
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9480
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9950
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4053
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
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.