SIGN UP MEMBER LOGIN:    
ARTICLE

Display User's Clipboard Image Into Picturebox Control

Posted by Ghanashyam Nayak Articles | Current Affairs April 22, 2011
This article shows how you can display an image from the clipboard in a picture box control of a form.
Reader Level:


Before explaining the primary subject of this article we will introduce the function which will be used in our article.

Clipboard.ContainsImage():

  • First of all it returns a Boolean type that means either "true" or "false".
  • Indicates whether there is data on the clipboard that is in the System.Windows.Forms.DataFormats.Bitmap format or that can be converted to that format.

Clipboard.GetImage():
  • It returns the image itself.
  • Retrieves the image from the clipboard.

PictureBoxSizeMode:
  • It is used to specify how an image is positioned within a System.Windows.Forms.PictureBox.
  • There are a total of five possible types of "SizeMode" for the "Picturebox" Control.

    o Normal
    o StretchImage
    o AutoSize
    o CenterImage
    o Zoom
     
  • For more understanding of the "SizeModes" see the images below:

    pictureBox1.SizeMode = PictureBoxSizeMode.Normal;

    Picture1.gif

    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

    Picture2.gif

    pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;

    Picture3.gif

    pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;

    Picture4.gif

    pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;

    Picture5.gif


Code :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DisplayClipboardImage
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {

            if (Clipboard.ContainsImage())
            {

pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

pictureBox1.Image = Clipboard.GetImage();
            }
            else
            {
MessageBox.Show("Clipboard is empty. Please Copy Image.");
            }
        }
    }
}

 

Login to add your contents and source code to this article
share this article :
post comment
 

thank you sir...

Posted by Ghanashyam Nayak Apr 22, 2011

Nice Article .

Posted by Prabhakar Parihar Apr 22, 2011
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor