Link to home
Start Free TrialLog in
Avatar of jumanac14
jumanac14

asked on

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?  
Avatar of chinu1310
chinu1310
Flag of United States of America image

Sounds little confusing. Can you explore it a bit?
Avatar of jumanac14
jumanac14

ASKER

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?
If you want entire screen shot this is a one good article to look at.
http://www.developerfusion.co.uk/show/4630/
ASKER CERTIFIED SOLUTION
Avatar of p_davis
p_davis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
nm i see what you mean in paint.-- if i just use the windows viewer it basically just shows the rectangle of the button.
This solution works great! Thanks!