Sunday, 21 September 2014

Save Panel with Control Inside It as Image C#.net, VB.net in windows application

9/21/2014 - By Pranav Singh 2

This article will show you how you can save a panel as image with control inside the panel as image in windows application using c#.net and vb.net.


So for this article first we will create a new windows application and in this application we will add a panel control and some other control inside the panel control.



Now we will create a folder into our bin ->  debug folder.



Now we add the below code on button click event.

C#.Net:
using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                using (var bmp = new Bitmap(panel1.Width, panel1.Height))
                {
                    panel1.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
                    bmp.Save("Image/PanelImage.png");
                }
                MessageBox.Show("Image saved successfully.");
            }
            catch
            {
                MessageBox.Show("Error.....");
            }
        }
    }
}

VB.Net:
Imports System.Drawing
Imports System.Windows.Forms

Namespace WindowsFormsApplication1
    Partial Public Class Form1
        Inherits Form
        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs)
            Try
                Using bmp = New Bitmap(panel1.Width, panel1.Height)
                    panel1.DrawToBitmap(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height))
                    bmp.Save("Image/PanelImage.png")
                End Using
                MessageBox.Show("Image saved successfully.")
            Catch
                MessageBox.Show("Error.....")
            End Try
        End Sub
    End Class
End Namespace

In above code I have converted the panel into an image and saved it into the image folder. Herer check the output.




Now click on save button on success full save you will get success message. On error you will get error message.



Now check the image folder.

DOWNLOAD

About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

2 comments:

  1. Hi. How are you? I just wanted to inform that I can't can't download the examples. Could you please solve it? :) Thanks :)

    ReplyDelete

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top