Some problems understanding how to use e.HasMorePages and setting zoom

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 1899 Views - Last Post: 02 April 2013 - 06:04 AM Rate Topic: -----

#16 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2239
  • View blog
  • Posts: 9,409
  • Joined: 29-May 08

Re: Some problems understanding how to use e.HasMorePages and setting zoom

Posted 31 March 2013 - 03:29 PM

I think you are still misunderstanding the basic concepts.

All you are doing is setting the .HasMorePages some boolean value.
You can't raise it, it is not an event. Even if it was an event, you still couldn't raise it externally.
Events can only be raised by the class (or a class that inherits from it), it is defined in.

Do you know the difference between a property and an event?
Was This Post Helpful? 0
  • +
  • -

#17 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 30
  • View blog
  • Posts: 218
  • Joined: 25-April 11

Re: Some problems understanding how to use e.HasMorePages and setting zoom

Posted 31 March 2013 - 03:37 PM

well I wrote it wrong, sorry... this is due to my bad english.

you are right that i set a boolean value to this property. the result of setting it is, that the PrintPage-Event is fired again. If I did not understand this, my script would not work! But it does. I just do not know, if this is the best way of doing it or if there are better ones.
Was This Post Helpful? 0
  • +
  • -

#18 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3450
  • View blog
  • Posts: 10,649
  • Joined: 05-May 12

Re: Some problems understanding how to use e.HasMorePages and setting zoom

Posted 31 March 2013 - 06:51 PM

There is a better way. Use the output that comes out of that variant of MeasureString() that you are using, but in particular take advantage the characters fitted and lines filled.

http://msdn.microsof...y/957webty.aspx

In pseudo code:
Print button handler:
Compute page size.
Set current character position to be zero.

Print page handler:
Setup string format break on words, allowing multiple lines of output.
Let test string be Substring(current character index).
Pass test string to MeasureString().
current character index += charactersFitted;
e.HasMorePages = current char index < full text string length.
Draw test string.


Was This Post Helpful? 2
  • +
  • -

#19 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 30
  • View blog
  • Posts: 218
  • Joined: 25-April 11

Re: Some problems understanding how to use e.HasMorePages and setting zoom

Posted 01 April 2013 - 06:23 AM

Thank you Skydiver.

This helps. But why would you do it per character? What is the advantage?
Was This Post Helpful? 0
  • +
  • -

#20 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3450
  • View blog
  • Posts: 10,649
  • Joined: 05-May 12

Re: Some problems understanding how to use e.HasMorePages and setting zoom

Posted 01 April 2013 - 03:05 PM

Right now you are splitting the string and then measuring. This takes time and allocates a large amount of memory. By letting MeasureString() figure out where it wants to put in the line breaks, it will internally just iterate over the characters until none will fit within the layout area anymore. The only extra allocation you now have to do is to pick up the rest of the string that has not yet been rendered. 1 allocation versus X where X is the number of whitespaces you have between words.

Additionally, the pseudo code figures out what will fit within the rendering area in one call, rather than you repetitively adding strings until it doesn't fit.

Another benefit is that you maintain the original data. If your string had two words with more than one space between them, the pseudo code above will keep that information, unlike when you called Split() where the multiple spaces will be coalesced into a single space. If you are an old school typist who puts two spaces after periods, the pseudo code would retain the two spaces unlike the Split() code which will make the two spaces just one space.
Was This Post Helpful? 1
  • +
  • -

#21 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 30
  • View blog
  • Posts: 218
  • Joined: 25-April 11

Re: Some problems understanding how to use e.HasMorePages and setting zoom

Posted 02 April 2013 - 06:04 AM

This is exactly what I wanted to know. Thank you again!

I'll Change my code asap and post back here in.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2