Created
February 3, 2014 22:47
-
-
Save jerone/8794040 to your computer and use it in GitHub Desktop.
ClipboardFusion Marco WinForm Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Windows.Forms; | |
using System.Drawing; | |
using System.Collections.Generic; | |
public static class ClipboardFusionHelper | |
{ | |
private static String Truncate(String text, Int32 count=1) | |
{ | |
if (count > 0 && text.Length > count) | |
{ | |
return String.Format("{0}...", text.Substring(0, count - 3).Trim()); | |
} | |
return text; | |
} | |
private static List<TreeNode> LoadClipboard(){ | |
List<TreeNode> nodes = new List<TreeNode>(); | |
int i = 0; | |
String textItem; | |
while (MacroAPI.GetHistoryText(i++, out textItem)){ | |
//MessageBox.Show(textItem); | |
TreeNode treeNode = new TreeNode(); | |
treeNode.Name = i.ToString(); | |
treeNode.Text = Truncate(textItem.Trim(), 50); | |
treeNode.ToolTipText = textItem; | |
nodes.Add(treeNode); | |
} | |
return nodes; | |
} | |
public static string ProcessText(string text) | |
{ | |
Form form1 = new Form(); | |
form1.Text = "My Dialog Box"; | |
form1.HelpButton = true; | |
form1.FormBorderStyle = FormBorderStyle.FixedDialog; | |
form1.MaximizeBox = false; | |
form1.MinimizeBox = false; | |
form1.StartPosition = FormStartPosition.CenterScreen; | |
TreeView treeView = new TreeView(); | |
treeView.Location = new Point (10, 10); | |
treeView.Size = new Size(form1.Width - 24 - 2, 200); | |
treeView.Nodes.AddRange(LoadClipboard().ToArray()); | |
form1.Controls.Add(treeView); | |
Button closeBtn = new Button(); | |
closeBtn.Text = "Close"; | |
closeBtn.Location = new Point (form1.Width - closeBtn.Width - 15, form1.Height - closeBtn.Height - 35); | |
form1.Controls.Add(closeBtn); | |
form1.AcceptButton = form1.CancelButton = closeBtn; | |
Button refreshBtn = new Button(); | |
refreshBtn.Text = "Refresh"; | |
refreshBtn.Location = new Point (closeBtn.Left - closeBtn.Width - 10, closeBtn.Top); | |
refreshBtn.Click += delegate { | |
treeView.Nodes.Clear(); | |
treeView.Nodes.AddRange(LoadClipboard().ToArray()); | |
}; | |
form1.Controls.Add(refreshBtn); | |
Button clearBtn = new Button(); | |
clearBtn.Text = "Clear All"; | |
clearBtn.Location = new Point (refreshBtn.Left - refreshBtn.Width - 10, refreshBtn.Top); | |
//clearBtn.Location = new Point (refreshBtn.Left - refreshBtn.Width - 10, refreshBtn.Top); | |
clearBtn.Click += delegate { | |
if (MessageBox.Show("Are you sure you want to clear your clipboard?", "Confirm clearing clipboard", MessageBoxButtons.YesNo) == DialogResult.Yes) | |
{ | |
if(MacroAPI.ClearClipboard()) | |
{ | |
MacroAPI.ShowMessageInfo("Clearing clipboard succeeded."); | |
} else { | |
MacroAPI.ShowMessageError("Clearing the clipboard failed!"); | |
} | |
treeView.Nodes.Clear(); | |
treeView.Nodes.AddRange(LoadClipboard().ToArray()); | |
} | |
}; | |
form1.Controls.Add(clearBtn); | |
/* | |
TextBox textBox1 = new TextBox(); | |
textBox1.Location = new Point (10, 10); | |
textBox1.Size = new Size(form1.Width - 24 - 2, 100); | |
textBox1.Multiline = true; | |
form1.Controls.Add(textBox1); | |
*/ | |
form1.ShowDialog(); | |
return text ?? String.Empty; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.clipboardfusion.com/Discussions/View/macro-with-winform/?ID=cf439efc-83e1-4071-a542-b5a6f748346f