jumanac14
asked on
button control bitmap file C#
I need to create a bitmap from a button control ( System.Windows.Forms.Butto n ) 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?
Sounds little confusing. Can you explore it a bit?
ASKER
public Form1()
{
InitializeComponent();
System.Windows.Forms.Butto n 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?
{
InitializeComponent();
System.Windows.Forms.Butto
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/
http://www.developerfusion.co.uk/show/4630/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
nm i see what you mean in paint.-- if i just use the windows viewer it basically just shows the rectangle of the button.
ASKER
This solution works great! Thanks!