Siu,
I have this encapsulated in a routine that may be somewhat opaque but
here it is. Note that all my drawing routines take measurements in inches
and assume that the default (1/100th inch) measurement unit is used for the
Graphics. The following draws the string supplied in a rectangle with the
specified left, right, top, bottom coordinates using the specified brush and
font.
I can't really send the code that calls this out-of-house.
Ron Allen
public int PrintInRect(Graphics g, Brush b, Font f, float x, float y,
float xr, float yb, String s, StringFormat sFmt)
{
// arguments are supplied in inches and the default measurement is used
// places the left edge of the string at the supplied x location
// assume user has done a translatetransform on the graphics for the hard
margins
// x is the right hand edge of the rectangle to print in, xr is the
lefthand edge
// y is the top edge and yb is the bottom edge
float x1 = (100.0f * x); // convert to 100ths of inches
float y1 = (100.0f * y);
float x1r = (100.0f * xr);
float y1b = (100.0f * yb);
// make sure that these are all positive or zero
x1 = Math.Max(x1, 0.0f);
y1 = Math.Max(y1, 0.0f);
x1r = Math.Max(x1r, 0.0f);
y1b = Math.Max(y1b, 0.0f);
int nLines, nChars;
// create the RectangleF to draw in
RectangleF rect = new RectangleF(x1, y1, (x1r - x1), (y1b - y1));
// and the SizeF for measuring
SizeF sz = new SizeF((x1r - x1), (y1b - y1));
// measure lines and characters used. Note nChars is presently
disregarded.
g.MeasureString(s, f, sz, sFmt, out nChars, out nLines);
// draw in the desired rectangle with wrapping
g.DrawString(s, f, b, rect, sFmt);
return nLines; // get back the # of lines that this used
}
> Hi Ron,
> can you please send to me your code? It's difficult to me understanding
[quoted text clipped - 32 lines]
>>
>> Ron Allen