473,732 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

About PrintDocument

Hello!

In the main form I have a multiline textbox where I can enter text. This is
named textBoxEdit.
Below I have an eventHandler for event BeginPrint called OnBeginPrint for
object PrintDocument and
an event handler for event PrintPage here called OnPrintPage for object
PrintDocument.

In the eventhandler OnBeginPrint it seems to me that these statements
surrounded with []
[int i = 0;
char[] trimParam = { '\r' };

foreach (string s in lines)
lines[i++] = s.TrimEnd(trimP aram);]

can be removed because it works just the same without them.
The purpose with these statement is to remove carrige return.
Can somebody explain why these statement which remove carrige return for
every line has no effect
on the text that is printed.
private void OnBeginPrint(ob ject sender, PrintEventArgs e)
{
char[] param = { '\n' };
lines = textBoxEdit.Tex t.Split(param);

int i = 0;
char[] trimParam = { '\r' };

foreach (string s in lines)
lines[i++] = s.TrimEnd(trimP aram);
}

private void OnPrintPage(obj ect sender, PrintPageEventA rgs e)
{
int x = 20, y = 20;

while (linesPrined < lines.Length) //antal rader att printa
{
e.Graphics.Draw String(lines[linesPrined++],
new Font("Arial", 10), Brushes.Black, x, y+=15);

if (y <= e.PageBounds.He ight - 80)
{
e.HasMorePages = true;
return;
}
}

linesPrined = 0;
e.HasMorePages = false;
}

//Tony
Jul 10 '08 #1
1 1613
On Thu, 10 Jul 2008 09:30:00 -0700, Tony Johansson
<jo************ *****@telia.com wrote:
[...]
The purpose with these statement is to remove carrige return.
Can somebody explain why these statement which remove carrige return for
every line has no effect
on the text that is printed.
I'm not even sure that DrawString() does anything with a carriage return
in the string. But assuming it did, the carriage returns would appear
only at the end of each string, and thus would have no effect on the
actual output from DrawString() for each line.

I find it a bit odd that the code you posted is doing all that parsing
anyway. Given that the text is coming from a TextBox (apparently), I
would have thought that using the Lines property would be more appropriate
for this purpose.

Pete
Jul 10 '08 #2

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

Similar topics

3
5338
by: Palli Olafs | last post by:
Hi Is it possible to save the PrintDocument as file without using a printer?
1
2159
by: john sutor | last post by:
I am trying to print a simple document (.txt) from my drive. I tried using the following code to no avail. This cannot be that hard. In VB this was easy, Why does C# make it so hard? Can anyone help me solve this. I ran the code from the clikc event of a button PrintDocument prnDc = new PrintDocument(); prnDc.DocumentName="c:\\Test1.txt"; prnDc.Print();
1
2415
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 in the wrong place?
1
1336
by: Just Me | last post by:
PageSetupDialog has a property "Document" of type "PrintDocument" It also has properties PageSettings and PrinterSettings PrintDocument also has these 2 properties. How are these different then the ones in "PrintDocument" Before I call a PageSetupDialog does it make sense to set all 3 ? After I call a PageSetupDialog where do I look for the changes? Confused Thanks for any help
0
1409
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
6319
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
28525
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 11") I'm passing these Rectangle properties into a method that is drawing thinking it's working...
2
6621
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 MSDN : "The FromPage, ToPage and PrintRange can also be set programmatically,
2
3904
by: Kool-Aide | last post by:
Alright, here goes...When I put a menu strip on the windows form I can double click the exit button to go to the source page and it takes me to the on click exit blah blah blah and you would put Application.Exit(); Alright well what would I put for the print preview and the print and Save and saveas and open and new? I can't find anything for these. I am new at this and I am sure I am not going in the correct order to learn this stuff but I...
0
8944
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8773
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
9306
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8186
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6030
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();...
0
4548
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2177
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.