Link to home
Start Free TrialLog in
Avatar of ampflp
ampflpFlag for United States of America

asked on

C# Clipboard - need data persistence after application is closed

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?
Avatar of systan
systan
Flag of Philippines image

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?
Avatar of Mike Tomlinson
Agreed...post your code as data I place on the clipboard is still there when my app closes.
Avatar of ampflp

ASKER

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

That should work...do you have any third-party clipboard managers installed or anything like that on your system?
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
Avatar of ampflp

ASKER

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)
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
good catch
Avatar of ampflp

ASKER

I missed that one - thank you so much. -