[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C# Clipboard - need data persistence after application is closed

Posted on 2011-04-22
9
Medium Priority
?
495 Views
Last Modified: 2013-12-16
I am writing a simple c# (VS2005) application to put data on a clipboard from a listbox. It is all working correctly - I can paste the data from the clipboard into wordpad, etc.  
The problem comes when I close my C# application.  The data disappears from the clipboard.  I would like it to be persistent.  I assumed since it was on the system clipboard, it would be available until something else was put on the clipboard.   But - it is no longer there.
Is there any way to keep it?
0
Comment
Question by:ampflp
  • 3
  • 3
  • 3
9 Comments
 
LVL 14

Expert Comment

by:systan
ID: 35448712
there are many links that can help you with that, one example is;
http://www.radsoftware.com.au/articles/clipboardmonitor.aspx
But
at least paste your code snippet?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35448720
Agreed...post your code as data I place on the clipboard is still there when my app closes.
0
 

Author Comment

by:ampflp
ID: 35449031
Here's the code -
		private void btnCopyAll_Click(object sender, System.EventArgs e)
		{
			StringBuilder sb = new StringBuilder();
			foreach (String str1 in msgList)
			{
				sb.Append(str1);
				sb.Append("\r\n");
			}
			
			String outString = sb.ToString();
			
			Clipboard.SetDataObject(outString);
		}

Open in new window

0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35449052
That should work...do you have any third-party clipboard managers installed or anything like that on your system?
0
 
LVL 14

Expert Comment

by:systan
ID: 35449122
use;
Clipboard.SetText
http://msdn.microsoft.com/en-us/library/tbfb3z56.aspx

why convert to string while there is a direct way of using a clipboard string

OR

find;
Clipboard.Clear
It's impossible that the clipboard is gone without clearing it.

OR

issue a;
Clipboard.Clear, to clear the clipboard first before another one
0
 

Author Comment

by:ampflp
ID: 35449127
oh - Office Clipboard is in the taskbar icon list - could that be interfering somehow?   (I am new to this work computer, don't know if there's something else hiding out)
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 35449155
Hmm...see: http://msdn.microsoft.com/en-us/library/cs5ebdfz.aspx

    "If the copy parameter is false, the data will be deleted from system Clipboard when the application exits."

So try this instead:

    Clipboard.SetDataObject(outString, true);
0
 
LVL 14

Expert Comment

by:systan
ID: 35449247
good catch
0
 

Author Closing Comment

by:ampflp
ID: 35449271
I missed that one - thank you so much. -
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question