0

I already saw this question but it doesn’t help me.

The problem is that I can write the text to the PDF file, but if I do that with a new gfx.DrawString it put the second text on the first... like this....

Here is my code I used to set a new line:

gfx.DrawString(lbname.Text + " " + lbnamei.Text, font, XBrushes.Black, new XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
gfx.DrawString(lbvorname.Text + " " + lbvornamei.Text, font, XBrushes.Black, new XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);

I think it has something to do with the numbers in the first argument (new XRect(0, 0,) but it is unclear how to set them.

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Dennis
  • 13
  • 1
  • 6

2 Answers2

0

I can't remember which parameter does which, but this will help you discover for yourself:

Set one of the numbers to 20 on one of the pieces of text; observe the effect. Then change it back and change a different number; observe the effect.

pete the pagan-gerbil
  • 3,136
  • 2
  • 28
  • 49
  • yes you are right. the value is 20 and for each line you need to add 20. it is the second value which gives you the line. so i have set the values to 20, 40, 60, etc.... thank you very much for your help (: – Dennis Aug 25 '15 at 09:32
0

An XRect has the four parameters x, y, width, height. x is the position from the left, y is the position from the top.

Width and height have no effect as long as XStringFormats.TopLeft is used. Therefore it is enough with the code shown above to increment y to draw text in a new line.

Width must be set to have text that is right-aligned or horizontally centered.
Height must be set to have text that is bottom-aligned or vertically centered.

  • Thanks for this explicit answer. But why you dont give this information on your website? It is very complicated to find any explanations to your pdf solution... – Dennis Aug 26 '15 at 12:55
  • We think that programmers will see `new XRect(...)` and will press F12 while on "XRect" to find "public XRect(double x, double y, double width, double height)". What more information do you need? Type "new XRect(" in VS and VS will show this information. The web site explains the basic principles, details are documented in the source code so VS can show the information where it is needed - without searching the web site. – I liked the old Stack Overflow Aug 26 '15 at 14:22