Hello Every body!
I copied the code from post http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1606666&SiteID=1
to save rtb as bmp. But This code is not being compiled. Message appears that FormateRange is missing reference.
Please tell me what to do for this error.
// Convenient overload
public
static Bitmap RtbToBitmap(Control rtb){
return RtbToBitmap(rtb,rtb.ClientRectangle.Width,
rtb.ClientRectangle.Height);
}
// Capture
public
Bitmap RtbToBitmap(Control rtb, int width, int height){
Bitmap bmp = new Bitmap(width, height);
using (Graphics gr = Graphics.FromImage(bmp))
{
IntPtr hDC = gr.GetHdc();
FORMATRANGE fmtRange;
RECT rect;
int fromAPI;
rect.Top = 0; rect.Left = 0;
rect.Bottom = (int)(bmp.Height
+ (bmp.Height * (bmp.HorizontalResolution / 100))
* inch);
rect.Right = (int)(bmp.Width
+ (bmp.Width * (bmp.VerticalResolution / 100))
* inch);
fmtRange.chrg.cpMin = 0;
fmtRange.chrg.cpMax = -1;
fmtRange.hdc = hDC;
fmtRange.hdcTarget = hDC;
fmtRange.rc = rect;
fmtRange.rcPage = rect;
int wParam = 1;
IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange));
Marshal.StructureToPtr(fmtRange, lParam, false);
fromAPI = SendMessage(rtb.Handle, EM_FORMATRANGE, wParam, lParam);
Marshal.FreeCoTaskMem(lParam);
fromAPI = SendMessage(rtb.Handle, EM_FORMATRANGE,
wParam, new IntPtr(0));
gr.ReleaseHdc(hDC);
}
return bmp;
}