divide by zero or some such thing and catching it someplace else. Have you
All new articles provide code in C# and VB.NET.
"zhaounknown" <zhaounknown@discussions.microsoft.com> wrote in message
news:9B188AC6-3884-41FB-8F6E-AB6D7E25788D@microsoft.com...
> When I comment out to be the following, it still doesnot work. The
> leftInch=3.5 inch, the topInch=3.8inch. When I further comment out the
> leftInch and rightInch statements, it prints. What's the reason?
>
> private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
> {
> Font newFont= new System.Drawing.Font("Arial", 10F,
> System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
> ((System.Byte)(134)));
>
> e.Graphics.PageUnit=GraphicsUnit.Inch;//
> float
> leftInch=(float)(this.textBox1.Left*1.0/this.pictureBox1.Image.Width*8.5);
> float
> topInch=(float)(this.textBox1.Top*1.0/this.pictureBox1.Image.Height*11.0);
>
> e.Graphics.DrawString("X", newFont, Brushes.Black, 0.5F, 0.6F);
> }
>
> Another question: the destination and source rectangles in
> PaintEventrgs.DrawImage() should be in measure unit defined by the
> GraphicsUnit parameter or by the external e.Graphics.PageUnit?
>
> Does DrawString takes the rectangle or pointF parameters in measure unit
> defined by Font's emsize generaly in Point or by the external
> e.Graphics.PageUnit?
>
> "Bob Powell [MVP]" wrote:
>
>> If you're printing then a real-world measurement system such as points,
>> millimeters or inches is best.
>>
>> Remember that the printer bounds are declared in 100ths of an inch. NOT
>> pixels. You need to multiply the printer bounds by the DPI to get the
>> real
>> pixel count if you want to use pixels at-all.
>>
>> I haven't the faintest idea what sort of values you're producing with
>> your
>> calculations on how the reciprocal width of a picturebox has a relation
>> to
>> the left edge of a textbox. This is more esoteric than quantum physics.
>> The
>> text doesn't show up because the result of that calculation puts it
>> outside
>> the page margins obviously.
>>
>> --
>> Bob Powell [MVP]
>> Visual C#, System.Drawing
>>
>> Find great Windows Forms articles in Windows Forms Tips and Tricks
>>
http://www.bobpowell.net/tipstricks.htm >>
>> Answer those GDI+ questions with the GDI+ FAQ
>>
http://www.bobpowell.net/faqmain.htm >>
>> All new articles provide code in C# and VB.NET.
>> Subscribe to the RSS feeds provided and never miss a new article.
>>
>>
>>
>>
>>
>> "zhaounknown" <zhaounknown@discussions.microsoft.com> wrote in message
>> news:7A138DA2-2217-4C11-8BDC-C1B879506E08@microsoft.com...
>> > 1. PaintEventArgs.Graphics.Drawstring() need to specify the upper-left
>> > coordinate for the text to be drawn. What measure unit should be used
>> > for
>> > the
>> > coordinate?
>> >
>> > 2. Why the following piece of code can't print the Texts (on letter
>> > paper)?
>> > However, if remove the "e.Graphics.PageUnit=GraphicsUnit.Inch;" and set
>> > 0.5F/0.6F to be 0.5*100 and 0.6*100 can work.
>> >
>> > private void printDocument1_PrintPage(object sender, PrintPageEventArgs
>> > e)
>> > {
>> > Font newFont= new System.Drawing.Font("Arial", 10F,
>> > System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
>> > ((System.Byte)(134)));
>> >
>> > e.Graphics.PageUnit=GraphicsUnit.Inch;//
>> > float
>> > leftInch=(float)(this.textBox1.Left*1.0/this.pictureBox1.Image.Width*8.5);
>> > float
>> > topInch=(float)(this.textBox1.Top*1.0/this.pictureBox1.Image.Height*11.0);
>> >
>> > e.Graphics.DrawString(this.textBox1.Text, this.textBox1.Font,
>> > Brushes.Black,
>> > leftInch, topInch);
>> >
>> > e.Graphics.DrawString("X", newFont, Brushes.Black, 0.5F, 0.6F);
>> > }
>>
>>
>>