Hello everybody
i want to display a form as thumbnail in the listview
for that i am using DrawToBitmap()
but it is not working for richtextbox and any com components
if i use CopyFromScreen() it is also capturing any contextmenus and filedialogs
please help me
regards
Ramana kumar

displaying form as image
zoranj
Ramana,
Take a look at this article from Ken Getz: http://www.mcwtech.com/CS/blogs/keng/archive/2005/12/16/137.aspx
It has code that uses the bitblt API method to copy the screen bit by bit. I tested it and it works on the richtextbox, but I'm not sure about com components (I tried with a vb6 listview, but that works even with drawtobitmap, so that's no reference).
The code in the article is in vb, but it will not be that hard to convert it to c#, try http://www.carlosag.net/Tools/CodeTranslator/Default.aspx
Hope this helps,
Chris G. Jones
Hi,
Is your problem solved
Bhanu.
SPWilkinson
hello bhanu
no it is not solved.
i am managing this with copyfromscreen but it is having problems like displaying dialogs and contextmenus
plese help me.
regards,
Ramana kumar.
AdrianG
hello
Sven De Bont
thank you very much for your response,
it is also working similar to CopyFromScreen() method
it is capturing any contextmenus and folder dialogs
i have to avoid those things
again thanks,
regards
Ramana kumar
Xancholy
To be complete, here's the c# code (tested):
// One of the many constants that modify
// the behavior of the BitBlt API:
private int SRCCOPY = 13369376;
// (DWORD) dest = source
[System.Runtime.InteropServices.DllImport("gdi32.dll", EntryPoint = "BitBlt")]
private static extern int BitBlt(IntPtr hDestDC, int x, int y, int nWidth,
int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop);
public Bitmap GetFormImage(Form frm) {
Bitmap bmp = null;
Graphics formGraphics = null;
Graphics memoryGraphics = null;
IntPtr dc1 = IntPtr.Zero;
IntPtr dc2 = IntPtr.Zero;
try {
formGraphics = frm.CreateGraphics();
// Create a bitmap big enough to contain
// the entire form, and retrieve a Graphics
// object that can work with the bitmap:
Size sz = frm.Size;
bmp = new Bitmap(sz.Width, sz.Height, formGraphics);
memoryGraphics = Graphics.FromImage(bmp);
// Retrieve the two drawing context handles (HDCs)
// dc1 represents the form
// dc2 represents the new bitmap
dc1 = formGraphics.GetHdc();
dc2 = memoryGraphics.GetHdc();
// Copy the image to dc2,
// using rectange 0, 0, sz.Width, sz.Height
// from dc1
// copy from the upper-left corner
BitBlt(dc2, 0, 0, sz.Width, sz.Height, dc1, ((1 * SystemInformation.FrameBorderSize.Width)
* -1), ((1
* (SystemInformation.FrameBorderSize.Height + SystemInformation.CaptionHeight))
* -1), SRCCOPY);
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}
finally {
if (!(formGraphics == null)) {
formGraphics.ReleaseHdc(dc1);
formGraphics.Dispose();
}
if (!(memoryGraphics == null)) {
memoryGraphics.ReleaseHdc(dc2);
memoryGraphics.Dispose();
}
}
return bmp;
}
Casius211362
Hi Ramana,
I found the following information in the documenatation of the DrawToBitmap method:
I'm not that familiar with this myself and couldn't find any information on the net (I only did a quick search). Hopefully this gets you on the way or maybe someone else can come up with an example.
Regards,