Click here to Skip to main content
15,884,014 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi dears.

I have a form that with some content that I want to allow my users to save as a bitmap or jpeg. I have a Save button that when the user clicks it, like to take a snapshot of that form content (without border and controlbox) and have a Save File Dialog open up that allows the user to decide where they want to save the file.
Posted

Save the Form & other controls as Bitmap[^]

This code is checked and working at least for me. Also provided example of SaveFileDialog usage.

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Load+=new EventHandler(Form1_Load);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                SaveAsBitmap(this, saveFileDialog.FileName);
            }
        }

        public void SaveAsBitmap(Control control, string fileName)
        {
            //getthe instance of the graphics from the control
            Graphics g = control.CreateGraphics();

            //new bitmap object to save the image
            Bitmap bmp = new Bitmap(control.Width, control.Height);

            //Drawing control to the bitmap
            control.DrawToBitmap(bmp, new Rectangle(0, 0, control.Width, control.Height));

            bmp.Save(fileName);
            bmp.Dispose();
        }
    }
 
Share this answer
 
v2
Comments
siasalar 9-Aug-12 2:49am    
Thanks a lot
siasalar 9-Aug-12 2:58am    
i want befor save file, ask for path and name
Roman Lerman 9-Aug-12 3:01am    
See the example code above.

<pre lang="cs">SaveFileDialog saveFileDialog = new SaveFileDialog();

if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
SaveAsBitmap(this, saveFileDialog.FileName);
}</pre>
 
Share this answer
 
Comments
siasalar 9-Aug-12 2:39am    
there is'nt any button to click.
It does'nt work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900