button control bitmap file C#

I need to create a bitmap from a button control ( System.Windows.Forms.Button ) and save it into a file.  Basically, I need to capture exactly how the button is being shown.  I am using C# 2005.  Please provide a sample code.  How can I do that?  
jumanac14Asked:
Who is Participating?
 
p_davisCommented:
how about
Bitmap myButtonBitmap = new Bitmap (myButton.Width, myButton.Height);
myButton.DrawToBitmap(myButtonBitmap, myButton.Bounds);
myButtonBitmap.Save(@"E:\myButtonBitmap.bmp" );
0
 
chinu1310Commented:
Sounds little confusing. Can you explore it a bit?
0
 
jumanac14Author Commented:
public Form1()
{
    InitializeComponent();

    System.Windows.Forms.Button myButton = new Button ();
    this.Controls.Add ( myButton );
    Bitmap myButtonBitmap = new Bitmap (myButton.Width, myButton.Height, myButton.CreateGraphics ( ));
    myButtonBitmap.Save ( @"E:\myButtonBitmap.bmp" );
}

What I would expect from this fragment of code is a bmp file that contains a "screen capture" of the button itself.  Instead, I'm just getting a file with a black background and nothing else.  What am I doing wrong?
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
chinu1310Commented:
If you want entire screen shot this is a one good article to look at.
http://www.developerfusion.co.uk/show/4630/
0
 
p_davisCommented:
nm i see what you mean in paint.-- if i just use the windows viewer it basically just shows the rectangle of the button.
0
 
jumanac14Author Commented:
This solution works great! Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.