Clipboard copy and paste

A

Alan T

Any source code example I can use to save the clipboard content to an
object, then I will do a copy and paste, finally put back the 'saved'
clipboard content back to clipboard ?
 
M

Michael C

Alan T said:
Any source code example I can use to save the clipboard content to an
object, then I will do a copy and paste, finally put back the 'saved'
clipboard content back to clipboard ?

Are you trying to use the clipboard to exchange data without the user doing
a copy-paste themselves?
 
B

beeswax

Use the System.Windows.Forms.Clipboard class and its static function.

Clipboard.GetDataObject(); returns the data that is currently in the
clipboard
Clipboard.SetDataObject("Test test"); allow you to put data in the
clipboard

there are also other usefull static functions to see what kind of data
you have in your clipboard!


ps: MSDN is the solution!
 
O

Oliver Sturm

Hello Alan,
Any source code example I can use to save the clipboard content to an
object, then I will do a copy and paste, finally put back the 'saved'
clipboard content back to clipboard ?

Let me just quickly say that I hate it when applications do this. If you
ask me, the clipboard is supposed to be an interactive functionality and I
(as the user) should be the only one to decide what's in the clipboard.

I have a real reason for this aversion, apart from principle: I'm using a
clipboard monitor tool (ClipMate), and in conjunction with applications
that modify the content of the clipboard for their own purposes, such
tools regularly go haywire - the clipboard content is being changed
several times in a very short timeframe, the tool tries to copy all the
content aside for later reuse, and so on. And in the end I have all kinds
of stuff in my clipboard history database that I can't really do anything
useful with.

Maybe I'm misunderstanding what you're trying to do, in that case please
forgive my rant :)


Oliver Sturm
 
A

Alan T

What I am trying to do is my application will do a copy some text/graphics
into clipboard and paste to another document.

By exiting my application, I need to restore the clipboard status as before
my application started.
So the pc user does not know his clipboard has been changed.
 
P

Peter Duniho

Alan T said:
What I am trying to do is my application will do a copy some text/graphics
into clipboard and paste to another document.

By exiting my application, I need to restore the clipboard status as
before my application started.
So the pc user does not know his clipboard has been changed.

The clipboard changes the moment you copy some data to it. Unless you have
some way to prevent the user from using his computer until your application
exits, you still have the risk of the user knowing that his clipboard has
been changed (and in particular, without his knowledge or consent and
possibly trashing, even if only temporarily, important data that he put
there on purpose).

Oliver's comments are exactly right. It is not appropriate to change the
clipboard without the user's explicit instruction. If you need to move data
from one document to another without the user's intervention, you need to do
so without using the clipboard. There should be no need to use the
clipboard anyway, and there are very good reasons not to for this purpose.

Pete
 
O

Otis Mukinfus

What I am trying to do is my application will do a copy some text/graphics
into clipboard and paste to another document.

By exiting my application, I need to restore the clipboard status as before
my application started.
So the pc user does not know his clipboard has been changed.

Hmmmm..... I think I agree with Oliver. I don't want any applications copying
data from my documents to another without my knowledge....

Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
A

Alan T

Sorry, I need to make myself clear:

In my application, I will create a new document.
The application will copy a part of another document (this will occupy the
clipboard) and paste to the new document.
Then application exit.

I need to restore the clipboard so that the pc user still keep the clipboard
content before the application started.
 
P

Peter Duniho

Alan T said:
Sorry, I need to make myself clear:

In my application, I will create a new document.
The application will copy a part of another document (this will occupy the
clipboard) and paste to the new document.
Then application exit.

Well, the various comments still apply. Your application should not be
automatically invoking the clipboard without the user's intervention,
assuming it is running in an environment where there is actually a user to
intervene.

If there is no such user, then preserving the clipboard is not important.
If there is such a user, then the operation should occur only through the
explicit and manual actions of the user.

Pete
 
A

Alan T

Hmmmm..... I think I agree with Oliver. I don't want any applications
Sorry, I think you are talking about rational things.

I want to be in a technical side or programming matters.


The end user knows he is copying part of a document to another document, ie
merge the documents, this is what my application supposed to do. These
things are behind the scenes. There are many things in the modern days
application without the user's notice.
The document is not what you think the user's document, that's part of the
application only specified by the user in the application.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top