Advertisement
jerone

ClipboardFusion Marco WinForm Test

May 21st, 2013
78
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. using System.Collections.Generic;
  5.  
  6. public static class ClipboardFusionHelper
  7. {
  8.     private static String Truncate(String text, Int32 count=1)
  9.     {
  10.         if (count > 0 && text.Length > count)
  11.         {
  12.             return String.Format("{0}...", text.Substring(0, count - 3).Trim());
  13.         }
  14.         return text;
  15.     }
  16.    
  17.     private static List<TreeNode> LoadClipboard(){
  18.         List<TreeNode> nodes = new List<TreeNode>();
  19.         int i = 0;
  20.         String textItem;
  21.         while (MacroAPI.GetHistoryText(i++, out textItem)){
  22.             //MessageBox.Show(textItem);
  23.             TreeNode treeNode = new TreeNode();
  24.             treeNode.Name = i.ToString();
  25.             treeNode.Text = Truncate(textItem.Trim(), 50);
  26.             treeNode.ToolTipText = textItem;
  27.             nodes.Add(treeNode);
  28.         }
  29.         return nodes;
  30.     }
  31.    
  32.     public static string ProcessText(string text)
  33.     {
  34.         Form form1 = new Form();
  35.         form1.Text = "My Dialog Box";
  36.         form1.HelpButton = true;
  37.         form1.FormBorderStyle = FormBorderStyle.FixedDialog;
  38.         form1.MaximizeBox = false;
  39.         form1.MinimizeBox = false;
  40.         form1.StartPosition = FormStartPosition.CenterScreen;
  41.  
  42.         TreeView treeView = new TreeView();
  43.         treeView.Location = new Point (10, 10);
  44.         treeView.Size = new Size(form1.Width - 24 - 2, 200);
  45.         treeView.Nodes.AddRange(LoadClipboard().ToArray());
  46.         form1.Controls.Add(treeView);
  47.        
  48.         Button closeBtn = new Button();
  49.         closeBtn.Text = "Close";
  50.         closeBtn.Location = new Point (form1.Width - closeBtn.Width - 15, form1.Height - closeBtn.Height - 35);
  51.         form1.Controls.Add(closeBtn);
  52.         form1.AcceptButton = form1.CancelButton = closeBtn;
  53.  
  54.         Button refreshBtn = new Button();
  55.         refreshBtn.Text = "Refresh";
  56.         refreshBtn.Location = new Point (closeBtn.Left - closeBtn.Width - 10, closeBtn.Top);
  57.         refreshBtn.Click += delegate {
  58.             treeView.Nodes.Clear();
  59.             treeView.Nodes.AddRange(LoadClipboard().ToArray());
  60.         };
  61.         form1.Controls.Add(refreshBtn);
  62.        
  63.         Button clearBtn = new Button();
  64.         clearBtn.Text = "Clear All";
  65.         clearBtn.Location = new Point (refreshBtn.Left - refreshBtn.Width - 10, refreshBtn.Top);
  66.         //clearBtn.Location = new Point (refreshBtn.Left - refreshBtn.Width - 10, refreshBtn.Top);
  67.         clearBtn.Click += delegate {
  68.             if (MessageBox.Show("Are you sure you want to clear your clipboard?", "Confirm clearing clipboard", MessageBoxButtons.YesNo) == DialogResult.Yes)
  69.             {
  70.                 if(MacroAPI.ClearClipboard())
  71.                 {
  72.                     MacroAPI.ShowMessageInfo("Clearing clipboard succeeded.");
  73.                 } else {
  74.                     MacroAPI.ShowMessageError("Clearing the clipboard failed!");
  75.                 }
  76.                 treeView.Nodes.Clear();
  77.                 treeView.Nodes.AddRange(LoadClipboard().ToArray());
  78.             }
  79.         };
  80.         form1.Controls.Add(clearBtn);
  81.        
  82. /*
  83.         TextBox textBox1 = new TextBox();
  84.         textBox1.Location = new Point (10, 10);
  85.         textBox1.Size = new Size(form1.Width - 24 - 2, 100);
  86.         textBox1.Multiline = true;
  87.         form1.Controls.Add(textBox1);
  88. */
  89.  
  90.         form1.ShowDialog();
  91.  
  92.         return text ?? String.Empty;
  93.     }
  94. }
Advertisement
RAW Paste Data Copied
Advertisement