[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

button control bitmap file C#

Posted on 2007-08-03
6
Medium Priority
?
237 Views
Last Modified: 2013-12-17
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?  
0
Comment
Question by:jumanac14
  • 2
  • 2
  • 2
6 Comments
 
LVL 14

Expert Comment

by:chinu1310
ID: 19627237
Sounds little confusing. Can you explore it a bit?
0
 

Author Comment

by:jumanac14
ID: 19627359
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
 
LVL 14

Expert Comment

by:chinu1310
ID: 19627382
If you want entire screen shot this is a one good article to look at.
http://www.developerfusion.co.uk/show/4630/
0
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
LVL 22

Accepted Solution

by:
p_davis earned 2000 total points
ID: 19627821
how about
Bitmap myButtonBitmap = new Bitmap (myButton.Width, myButton.Height);
myButton.DrawToBitmap(myButtonBitmap, myButton.Bounds);
myButtonBitmap.Save(@"E:\myButtonBitmap.bmp" );
0
 
LVL 22

Expert Comment

by:p_davis
ID: 19627907
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
 

Author Comment

by:jumanac14
ID: 19629008
This solution works great! Thanks!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Screencast - Getting to Know the Pipeline
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question