1. 程式人生 > 其它 >C# 資料複製到貼上板

C# 資料複製到貼上板

using SoftRGB.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Yang.Common.Helper
{
    public static class ClipboardHelper
    {
        /// <summary>
        /// 資料複製到系統貼上板
        /// add  by yangxp@20180528 
        
/// </summary> /// <param name="data">待複製資料</param> /// <param name="times">嘗試次數</param> /// <returns>是否成功</returns> public static bool CopyData(string data, int times) { try { bool result = false
; if (string.IsNullOrEmpty(data)) return false; else { System.Windows.Forms.Clipboard.SetDataObject(data.ToString(), true, 3, 100); result = true; } return result; }
catch (Exception ex) { RGBMessageBox.Show("複製失敗:剪貼簿被其他執行緒或應用程式佔用。\n" + ex.Message, mesBoxType: RGBMesType.Error); return false; } } } }

轉 :https://blog.csdn.net/qq_23018459/article/details/80483132