umm
maybe if i'll show you the code i'll explain better:
Graphics g=this.outputrichbox.CreateGraphics();
g.PageUnit=GraphicsUnit.Inch;
g.PageScale=1;
PointF[] bottom=new PointF[3];
bottom[0]=new PointF((float)this.pageSetupDialog1.PageSettings.PaperSize.Width/100,1);
bottom[1]=new PointF((float)this.pageSetupDialog1.PageSettings.Margins.Left/100,1);
bottom[2]=new PointF((float)this.pageSetupDialog1.PageSettings.Margins.Right/100,1); g.TransformPoints(CoordinateSpace.Device,CoordinateSpace.Page,bottom);
g.Dispose();
int pixelix=(int)bottom[0].X;
this.outputrichbox.ClientSize=new Size(pixelix,this.outputrichbox.ClientSize.Height);
pixelix=(int)bottom[1].X; this.outputrichbox.SelectionIndent=pixelix;
pixelix=(int)bottom[2].X; this.outputrichbox.SelectionRightIndent=pixelix;
this.Refresh();
this.outputrichbox is the box i'm trying to get it resized and indented. before i do this i copy it's exact Rtf into another box and that one i print. the resizing seems to be ok but when i compare the texts not everything is allright.
this is what i use to print the contents:
public int Print( int charFrom, int charTo,PrintPageEventArgs e)
{
//Calculate the area to render and print
RECT rectToPrint;
rectToPrint.Top = (int)(e.MarginBounds.Top * anInch);
rectToPrint.Bottom = (int)(e.MarginBounds.Bottom * anInch);
rectToPrint.Left = (int)(e.MarginBounds.Left * anInch);
rectToPrint.Right = (int)(e.MarginBounds.Right * anInch);
//Calculate the size of the page
RECT rectPage;
rectPage.Top = (int)(e.PageBounds.Top * anInch);
rectPage.Bottom = (int)(e.PageBounds.Bottom * anInch);
rectPage.Left = (int)(e.PageBounds.Left * anInch);
rectPage.Right = (int)(e.PageBounds.Right * anInch);
IntPtr hdc = e.Graphics.GetHdc();
FORMATRANGE fmtRange;
fmtRange.chrg.cpMax = charTo; //Indicate character from to character to
fmtRange.chrg.cpMin = charFrom;
fmtRange.hdc = hdc; //Use the same DC for measuring and rendering
fmtRange.hdcTarget = hdc; //Point at printer hDC
fmtRange.rc = rectToPrint; //Indicate the area on page to print
fmtRange.rcPage = rectPage; //Indicate size of page
IntPtr res = IntPtr.Zero;
IntPtr wparam = IntPtr.Zero;
wparam = new IntPtr(1);
//Get the pointer to the FORMATRANGE structure in memory
IntPtr lparam= IntPtr.Zero;
lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange));
Marshal.StructureToPtr(fmtRange, lparam, false);
//Send the rendered data for printing
res = SendMessage(Handle, EM_FORMATRANGE, wparam, lparam);
//Free the block of memory allocated
Marshal.FreeCoTaskMem(lparam);
//Release the device context handle obtained by a previous call
e.Graphics.ReleaseHdc(hdc);
//Return last + 1 character printer
return res.ToInt32();
}