Whilst working on Ajax Snippets I wanted to provide an option for the user in a DesignerActionList to copy some javascript function stubs to the clipboard, at first I was stumped, I have worked with clipboard data before but I could not remember how to do it let alone the environment was giving me doubts to wether the answer was the same as working with winforms.
Like winforms you can get at the clipboard via the not suprisingly named Clipboard class.
[code:c#]
public class MyDesigner : ControlDesigner
{
public override DesignerActionListCollection ActionLists
{
get
{
DesignerActionListCollection actionLists = new DesignerActionListCollection();
actionLists.AddRange(base.ActionLists);
actionLists.Add(new MyDesignerActionList(this));
return actionLists;
}
}
}
public class MyDesignerActionList : DesignerActionList
{
MyDesigner _Designer;
DesignerActionItemCollection _Items;
public MyDesignerActionList(MyDesigner designer) : base(designer.Component)
{
_Designer = designer;
}
public void SetClipboard()
{
Clipboard.SetDataObject("Hello World");
}
public override DesignerActionItemCollection GetSortedActionItems()
{
if (_Items == null)
{
_Items = new DesignerActionItemCollection();
_Items.Add(new DesignerActionMethodItem(this, "SetClipboard", "Set clipboard"));
}
return _Items;
}
}
[/code]