By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,996 Members | 1,179 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,996 IT Pros & Developers. It's quick & easy.

How to create bitmap of window form.

P: n/a
Hi,

How can i create bitmap of a window form with all its child controls
without showing this form?
1. I am trying to create bitmap image of a window form.
2. I am creating a new instance of Form at runtime.
3. Then adding several controls like Button, RadioButton,CheckBox etc
to it.
4. Now i want to create bitmap with all controls showing on it which
are added to this form.
I am trying it by Control.DrawToBitmap().But in this way i am not
getting the controls in that bitmap of the form which are added to
it.But when i am showing the form , all controls appears in the
bitmap.But i want such bitmap without showing form or being visible.
How can i make it possible? Kindly reply ASAP.

Aug 1 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Melisa,

The reason this doesn't work is because without making the form visible,
it doesn't create the child controls (at least, the windows handles for the
child controls).

To get around this, you will have to create the handle for the form, and
then create the handle for each child control in the form. The easiest way
to do this would be to recursively cycle through the controls on the form,
and then all of its controls, etc, etc.

To get the handle, just assign the Handle property of the control to a
dummy variable.

Then, when you call DrawToBitmap, it should turn out just fine.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Melisa" <pr*************@nagarro.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hi,

How can i create bitmap of a window form with all its child controls
without showing this form?
1. I am trying to create bitmap image of a window form.
2. I am creating a new instance of Form at runtime.
3. Then adding several controls like Button, RadioButton,CheckBox etc
to it.
4. Now i want to create bitmap with all controls showing on it which
are added to this form.
I am trying it by Control.DrawToBitmap().But in this way i am not
getting the controls in that bitmap of the form which are added to
it.But when i am showing the form , all controls appears in the
bitmap.But i want such bitmap without showing form or being visible.
How can i make it possible? Kindly reply ASAP.

Aug 1 '06 #2

P: n/a
Nicholas Paldino [.NET/C# MVP] wrote:
Melisa,

The reason this doesn't work is because without making the form visible,
it doesn't create the child controls (at least, the windows handles for the
child controls).

To get around this, you will have to create the handle for the form, and
then create the handle for each child control in the form. The easiest way
to do this would be to recursively cycle through the controls on the form,
and then all of its controls, etc, etc.

To get the handle, just assign the Handle property of the control to a
dummy variable.

Then, when you call DrawToBitmap, it should turn out just fine.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Melisa" <pr*************@nagarro.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hi,

How can i create bitmap of a window form with all its child controls
without showing this form?
1. I am trying to create bitmap image of a window form.
2. I am creating a new instance of Form at runtime.
3. Then adding several controls like Button, RadioButton,CheckBox etc
to it.
4. Now i want to create bitmap with all controls showing on it which
are added to this form.
I am trying it by Control.DrawToBitmap().But in this way i am not
getting the controls in that bitmap of the form which are added to
it.But when i am showing the form , all controls appears in the
bitmap.But i want such bitmap without showing form or being visible.
How can i make it possible? Kindly reply ASAP.
Hi Nicholas,

Thanks , for your valuable suggestion. It is working that ways and it
has solved my problem to a great extent.
Still I have a confusion that why it is not working if I call "
Control.CreateControl() " method when we are able to create Handle for
the control by the same method.

Do you have any idea in this regard ??

Aug 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.