473,698 Members | 2,440 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 1609
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
5328
by: Palli Olafs | last post by:
Hi Is it possible to save the PrintDocument as file without using a printer?
1
2157
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
2413
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
1331
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
1408
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
6304
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
28508
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
6620
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
3900
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
8608
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
9161
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
9029
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...
1
8897
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8867
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
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
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
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
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.