about painting where I don't specify a rectangle

T

Tony Johansson

Hi!

If I set sf.Alignment = StringAlignment.Near; it will draw at the far left
which is correct
But when I set the sf.Alignment = StringAlignment.Far; in the code below no
text is displayed.
so I wonder if I don't specify a rectangle what is the area that .NET will
use to draw ?

Graphics g = this.CreateGraphics();
FontFamily fm = new FontFamily("Arial");
Font f = new Font(fm, 10);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Near;
g.DrawString("GDI+ in Microsoft .NET", f, Brushes.Red, 0, 0, sf);

//Tony
 
P

Peter Duniho

Tony said:
Hi!

If I set sf.Alignment = StringAlignment.Near; it will draw at the far left
which is correct
But when I set the sf.Alignment = StringAlignment.Far; in the code below no
text is displayed.
so I wonder if I don't specify a rectangle what is the area that .NET will
use to draw ?

The rectangle that contains the text you asked it to draw.

"Near" and "Far" are just "text-direction-agnostic" descriptions of
alignment. But if you know the text direction being used, you can tell
what alignment corresponds to each. For left-to-right text, "Far" is
just "right-aligned". So when you tell Graphics to draw your text
right-aligned at point (0, 0), it draws the text so that the right edge
of the text winds up at that point.

You'll see the text being drawn if you specify a location to draw it
that is not at the very left edge of the visible area of the Graphics
instance.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top