Click here to Skip to main content
16,022,418 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Happy New Year.

I am able to implement clipboard functionality and my doubt is can't we know from where the content is copied.

Scenario:

1.I am running the clipboard application.
2.Opened notepad and copied some content.
3.I am able to paste the content.

Here i want to paste the content and also display like it's copied from notepad if it is notepad or MS Word if it i Copied from MS Word.


My COde

C#
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 Clipboard1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }
        //copy Text
        private void button1_Click(object sender, EventArgs e)
        {
            Clipboard.SetDataObject(richTextBox1.SelectedText);

        }
        //Paste Text
        private void button2_Click(object sender, EventArgs e)
        {

            richTextBox1.Text= Clipboard.GetText().ToString();


            //if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text))
            //    textBox1.Text = Clipboard.GetDataObject().GetData(DataFormats.Text).ToString();
            //else
            //    textBox1.Text = "The clipboad does not contain any text";
            //////label1.Text = Clipboard.GetText();

            //// Retrieves data
            //IDataObject iData = Clipboard.GetDataObject();
            //// Is Data Text?
            //if (iData.GetDataPresent(DataFormats.Text))
            //    label1.Text = (String)iData.GetData(DataFormats.Text);
            //else
            //    label1.Text = "Data not found.";
        }

        //clearing ClipBoard
        private void button3_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
        }

        //Copy Image
        private void button4_Click(object sender, EventArgs e)
        {
            if (opnImage.ShowDialog() == DialogResult.OK)
            {
                Image imgToCopy = Image.FromFile(opnImage.FileName);
                Clipboard.SetImage(imgToCopy);
            }
        }

        //Paste Image

        private void button5_Click(object sender, EventArgs e)
        {
            picClipboard.Image = Clipboard.GetImage();
        }

    }
}
Posted
Updated 2-Jan-11 19:28pm
v3
Comments
Sergey Alexandrovich Kryukov 3-Jan-11 1:27am    
What is listed in your "scenario" is already available without any additional clipboard application.
Please describe what you want to achieve (and what you already done). How do you think what your application should do?

If you explain all that, it would make an good question and potentially interesting application. In the past, Windows was shipped with some kind of useful clipboard manager, I don't know why not anymore.
subhash04573 3-Jan-11 1:51am    
just it will copy the content or image. and it will paste the content in the richtextbox and image in the picturebox.
while pasting i need to diplay the owner of the clipboard also.

1 solution

Check if there is a way to get the clip board owner.

For e.g. see this thread[^]. Its not in C#, but it might give you an idea of what I'm trying to say.
 
Share this answer
 

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