tags:

views:

45

answers:

1

I want to implement previews/thumbnails in my project, therefor i need the graphical output of a control as bitmap. I have a third party control which loads documents and displays them. Is it possible to fetch the output of an control and store it in a bitmap object without adding it to the UI? And If how?

Edit: I probably should said that before, but i don't know if that's important. The ThirdParty Control is an OCX(ActiveX control).

+1  A: 

in a Form do:

Bitmap myBitmap = new Bitmap(button1.Width, button1.Height);

// button1.Draw..., not 'this.Draw...'!
button1.DrawToBitmap(myBitmap, button1.DisplayRectangle); 

myBitmap.Save(@"C:\test.bmp");
serhio
He said _without adding it to the UI?_
John Knoeller
Thanks for your fast response, But it doesn't work as expected. I tried it with a button and i get Bitmap(size of the button) which shows the upper left conrner of the form(icon + titletext).
Marcel Benthin
same effect ...
Marcel Benthin
try once again avec le code MiseàJour. Finally, you can do it with any control using the Control.DrawToBitmap property. If your control is a AcX control, it may not have this method...
serhio
no, sry ... still the same
Marcel Benthin
I have tested this code on a button and it works. Take attention that DrawToBitmap is called by the **button**, not by the **form**, paste your code if it not works.
serhio
Thanks this works... now it has to work with the OCX too
Marcel Benthin
well, you can try to convert the OCX to Control or try to use the AcX methods..
serhio
If i replace the button with the OCX i get an InvalidActiveXStateException, which disappears if i add the OCX to the form. But then the Bitmap only contains a horizontal and vertical scrollbar. Maybe this doesn't work with OCX controls.
Marcel Benthin