我試圖使其中近5剪貼板中的文本複製才能剪貼板中的文本複製到陣列
5元素的數組列表,但我不能夠做到這一點,每次剪貼板文本覆蓋前一個和在第一個數組元素
並只打印最後一個我想打印所有我如何做到這一點。
如果我的情況是可能的THN請給我一些解決方案
我試圖使其中近5剪貼板中的文本複製才能剪貼板中的文本複製到陣列
5元素的數組列表,但我不能夠做到這一點,每次剪貼板文本覆蓋前一個和在第一個數組元素
並只打印最後一個我想打印所有我如何做到這一點。
如果我的情況是可能的THN請給我一些解決方案
如何:當你在Clipboard
讀/寫您管理的自定義對象。例如,MyCustomClipboardClass
。
每當您要將數據移至剪貼板時,
MyCustomClipboardClass
對象。如下圖:
[Serializable]
class MyCustomClipboardClass
{
List<string> m_lstTexts = new List<string>();
public void AddText(string str)
{
m_lstTexts.Add(str);
}
}
你可以做這樣的事情,如果我沒有理解問題正確(如果你想最後5個剪貼板項目保持編程):
const int MaxItems = 5;
static readonly List<string> ClipboardData = new List<string>();
public static void SaveClipboard()
{
ClipboardData.Add(Clipboard.GetText());
if (ClipboardData.Count > MaxItems) ClipboardData.RemoveAt(0);
}
// You don't need lines later, I show them just as example
[STAThreadAttribute]
static void Main()
{
for (int i = 0; i < 10; i++)
{
Clipboard.SetText(i.ToString());
SaveClipboard();
}
foreach (var s in ClipboardData)
{
Console.WriteLine(s);
}
Console.ReadLine();
}
如果您需要@KMan的方式也檢查這個問題:C#/WPF Can I Store more that 1 type in Clipboard?
所以你必須在每個剪貼板修改後調用SaveClipboard()。所有數據將收集在剪貼板數據
你可以顯示你的代碼,而不是問題描述? – 2010-10-24 12:41:48
您是否嘗試過使用String.Join(',',myArray) – Kane 2010-10-24 12:41:59
-1,因爲nobdy可以猜測您的代碼是如何工作的。在發佈之前考慮它。 – spender 2010-10-24 12:47:24