public void OnClipboardChange() { if (Clipboard.ContainsText()) { string text = Clipboard.GetText(); _ = new TextItem(this, text); } else if (Clipboard.ContainsFileDropList()) { StringCollection files = Clipboard.GetFileDropList(); _ = new FileItem(this, files); } else if (Clipboard.ContainsImage()) { Image image = Clipboard.GetImage(); _ = new ImageItem(this, image); } else if (Clipboard.ContainsAudio()) { Stream audio = Clipboard.GetAudioStream(); _ = new AudioItem(this, audio); } else { IDataObject data = Clipboard.GetDataObject(); _ = new CustomItem(this, data); } }
public static void FromFile() { // if CLIPBOARD file is missing or empty if (!LocalClipboard.ClipboardFile.Exists || LocalClipboard.ClipboardFile.Length == 0) { return; } // store the current contents of the clipboard file string clipboardString = LocalClipboard.GetClipboard(); // update the backup file with clipboardString LocalClipboard.BackupClipboard(clipboardString); // traverse clipboardString via StringReader using (StringReader strRead = new StringReader(clipboardString)) { // peek returns -1 if no more characters are available while (strRead.Peek() != -1) { // Type ClipboardItem.TypeEnum type = (ClipboardItem.TypeEnum)strRead.Read(); // KeyDiff ushort keyDiff = ushort.Parse(strRead.ReadLine()); // remaining operations depend on the type of item switch (type) { case ClipboardItem.TypeEnum.Text: _ = new TextItem(LocalClipboard.MainWindow, keyDiff, strRead); break; case ClipboardItem.TypeEnum.FileDropList: _ = new FileItem(LocalClipboard.MainWindow, keyDiff, strRead); break; case ClipboardItem.TypeEnum.Image: _ = new ImageItem(LocalClipboard.MainWindow, keyDiff, strRead); break; case ClipboardItem.TypeEnum.Audio: _ = new AudioItem(LocalClipboard.MainWindow, keyDiff, strRead); break; case ClipboardItem.TypeEnum.Custom: _ = new CustomItem(LocalClipboard.MainWindow, keyDiff, strRead); break; } } } }