From: AliR (VC++ MVP) on 12 Aug 2008 17:14 I think I got it: (thank you Peter for your help) public void Draw(Graphics graphics, RectangleF layoutArea, float xFactor) { //Calculate the area to render. SafeNativeMethods.RECT rectLayoutArea; rectLayoutArea.Top = (int)(0 * anInch); rectLayoutArea.Bottom = (int)(layoutArea.Bottom * anInch); rectLayoutArea.Left = (int)(0 * anInch); rectLayoutArea.Right = (int)(layoutArea.Right * anInch); Bitmap Bmp = new Bitmap((int)layoutArea.Width, (int)layoutArea.Height, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(Bmp); IntPtr hdc = g.GetHdc(); //create a metafile, convert the size to himetrics Metafile metafile = new Metafile(hdc, new RectangleF(0,0,layoutArea.Width*26,layoutArea.Height*26)); g.ReleaseHdc(hdc); g.Dispose(); g = Graphics.FromImage(metafile); IntPtr hDCEMF = g.GetHdc(); SafeNativeMethods.FORMATRANGE fmtRange; fmtRange.chrg.cpMax = -1; //Indicate character from to character to fmtRange.chrg.cpMin = 0; fmtRange.hdc = hDCEMF; //Use the same DC for measuring and rendering fmtRange.hdcTarget = hDCEMF; //Point at printer hDC fmtRange.rc = rectLayoutArea; //Indicate the area on page to print fmtRange.rcPage = rectLayoutArea; //Indicate size of page 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); SafeNativeMethods.SendMessage(this.Handle, SafeNativeMethods.EM_FORMATRANGE, wParam, lParam); //Free the block of memory allocated Marshal.FreeCoTaskMem(lParam); //Release the device context handle obtained by a previous call g.ReleaseHdc(hDCEMF); g.Dispose(); graphics.ScaleTransform(xFactor, xFactor); graphics.DrawImage(metafile, layoutArea.Location); } AliR.
First
|
Prev
|
Pages: 1 2 Prev: Adding an IP address to a network card Next: Unable to load DLL 'webengine.dll' |