By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,195 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

Clipboard copy and paste

P: n/a
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 ?
Dec 6 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
"Alan T" <al*************@yahoo.com.auwrote in message
news:ux**************@TK2MSFTNGP06.phx.gbl...
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?
>

Dec 6 '06 #2

P: n/a
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!

Alan T wrote:
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 ?
Dec 6 '06 #3

P: n/a
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
--
http://www.sturmnet.org/blog
Dec 6 '06 #4

P: n/a
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.

"Oliver Sturm" <ol****@sturmnet.orgwrote in message
news:xn****************@msnews.microsoft.com...
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
--
http://www.sturmnet.org/blog

Dec 6 '06 #5

P: n/a
"Alan T" <al*************@yahoo.com.auwrote in message
news:eV**************@TK2MSFTNGP02.phx.gbl...
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
Dec 6 '06 #6

P: n/a
On Thu, 7 Dec 2006 10:26:09 +1100, "Alan T" <al*************@yahoo.com.au>
wrote:
>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.

"Oliver Sturm" <ol****@sturmnet.orgwrote in message
news:xn****************@msnews.microsoft.com...
>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
--
http://www.sturmnet.org/blog
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
Dec 7 '06 #7

P: n/a
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.

"Peter Duniho" <Np*********@NnOwSlPiAnMk.comwrote in message
news:12*************@corp.supernews.com...
"Alan T" <al*************@yahoo.com.auwrote in message
news:eV**************@TK2MSFTNGP02.phx.gbl...
>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

Dec 7 '06 #8

P: n/a
"Alan T" <al*************@yahoo.com.auwrote in message
news:uU**************@TK2MSFTNGP02.phx.gbl...
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
Dec 7 '06 #9

P: n/a
>>Hmmmm..... I think I agree with Oliver. I don't want any applications
>>copying
data from my documents to another without my knowledge....
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.
Dec 7 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.