Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting bitmap of a user control in c#

Status
Not open for further replies.

smorken

Programmer
Dec 19, 2007
3
CA
Hi, I was wondering if anyone knows of way to take a bitmap snapshot of a user control. I have searched and found no way to do it yet.

The reason I want to do it is because I have a custom drawn user control and I want to make a disabled "grayed out" mode for it. I figure if I take a bitmap of it, apply a color transform to it, and put it where the control would be, it would be a better solution than changing all of the pen/brush colors and adding a lot of code to make the control non-functional.

Any ideas?

Scott
 
Using usercontrol1.Enabled = false;
has no effect since my user control is a custom drawn indicator only. It has no input. I just need to make it show that it is not currently active somehow, and graying it out seems like a good way.

If you are interested, there is a screen shot of the indicators and the code here: (it is the third project down)
 
control_pain(object sender, PaintEventArgs e)
{
//do your typical control drawing
e.Graphics.FillRectangle(Brushes.Red, 0,0,100,100);

if (!enabled)
{
//Draw a translucent black over the control to make it look disabled
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(Color.Black, 30)), 0,0,100,100);
}

}


 
For future reference - you are already drawing your control using the graphics object of the form. You can create a graphics object from a bitmap and draw to it directly.

something like this:

Bitmap bmp = new Bitmap(this.Width, this.Height); //make a bitmap the size of your control

Grapics g = Graphics.FromImage(bmp);

g.DrawLine(Pens.Black, 0,0,100,100);

//You are now drawing to your bitmap. You can save your bitmap at this point.

bmp.Save("C:\\MyFile.bmp");
or
bmp.Save("C:\\MyFile.jpg"); //etc

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top