本文整理汇总了C#中Microsoft.VisualStudio.OLE.Interop.IDataObject.SetData方法的典型用法代码示例。如果您正苦于以下问题:C# IDataObject.SetData方法的具体用法?C# IDataObject.SetData怎么用?C# IDataObject.SetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.OLE.Interop.IDataObject
的用法示例。
在下文中一共展示了IDataObject.SetData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PackageSelectionDataObject
/// <summary>
/// Returns a dataobject from selected nodes
/// </summary>
/// <param name="cutHighlightItems">boolean that defines if the selected items must be cut</param>
/// <returns>data object for selected items</returns>
internal virtual DataObject PackageSelectionDataObject(bool cutHighlightItems)
{
this.CleanupSelectionDataObject(false, false, false);
StringBuilder sb = new StringBuilder();
DataObject dataObject = null;
try
{
IList<HierarchyNode> selectedNodes = this.GetSelectedNodes();
if (selectedNodes != null)
{
this.InstantiateItemsDraggedOrCutOrCopiedList();
StringBuilder selectionContent = null;
// If there is a selection package the data
if (selectedNodes.Count > 1)
{
foreach (HierarchyNode node in selectedNodes)
{
selectionContent = node.PrepareSelectedNodesForClipBoard();
if (selectionContent != null)
{
sb.Append(selectionContent);
}
}
}
else if (selectedNodes.Count == 1)
{
HierarchyNode selectedNode = selectedNodes[0];
selectionContent = selectedNode.PrepareSelectedNodesForClipBoard();
if (selectionContent != null)
{
sb.Append(selectionContent);
}
}
}
// Add the project items first.
IntPtr ptrToItems = this.PackageSelectionData(sb, false);
if (ptrToItems == IntPtr.Zero)
{
return null;
}
FORMATETC fmt = DragDropHelper.CreateFormatEtc(DragDropHelper.CF_VSSTGPROJECTITEMS);
dataObject = new DataObject();
dataObject.SetData(fmt, ptrToItems);
// Now add the project path that sourced data. We just write the project file path.
IntPtr ptrToProjectPath = this.PackageSelectionData(new StringBuilder(this.GetMkDocument()), true);
if (ptrToProjectPath != IntPtr.Zero)
{
dataObject.SetData(DragDropHelper.CreateFormatEtc(DragDropHelper.CF_VSPROJECTCLIPDESCRIPTOR), ptrToProjectPath);
}
if (cutHighlightItems)
{
bool first = true;
IVsUIHierarchyWindow w = UIHierarchyUtilities.GetUIHierarchyWindow(this.site, HierarchyNode.SolutionExplorer);
foreach (HierarchyNode node in this.ItemsDraggedOrCutOrCopied)
{
ErrorHandler.ThrowOnFailure(w.ExpandItem((IVsUIHierarchy)this, node.ID, first ? EXPANDFLAGS.EXPF_CutHighlightItem : EXPANDFLAGS.EXPF_AddCutHighlightItem));
first = false;
}
}
}
catch (COMException e)
{
Trace.WriteLine("Exception : " + e.Message);
dataObject = null;
}
return dataObject;
}