本文整理汇总了C#中System.Windows.Forms.DataObject.SetFileDropList方法的典型用法代码示例。如果您正苦于以下问题:C# DataObject.SetFileDropList方法的具体用法?C# DataObject.SetFileDropList怎么用?C# DataObject.SetFileDropList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DataObject
的用法示例。
在下文中一共展示了DataObject.SetFileDropList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Send
public void Send(string archiveFilename, CancellationToken cancellationToken, SimpleProgressCallback progressCallback = null)
{
// create drop effect memory stream
byte[] moveEffect = new byte[] { (byte) (performCut ? 2 : 5), 0, 0, 0 };
MemoryStream dropEffect = new MemoryStream();
dropEffect.Write(moveEffect, 0, moveEffect.Length);
// create file data object
DataObject data = new DataObject();
data.SetFileDropList(new StringCollection { archiveFilename });
data.SetData("Preferred DropEffect", dropEffect);
// create STA thread that'll work with Clipboard object
Thread copyStaThread = new Thread(() =>
{
Clipboard.Clear();
Clipboard.SetDataObject(data, true);
})
{
Name = "Clipboard copy thread"
};
copyStaThread.SetApartmentState(ApartmentState.STA);
// start the thread and wait for it to finish
copyStaThread.Start();
copyStaThread.Join();
}
示例2: GetDataObject
public static DataObject GetDataObject(IEnumerable<string> paths, bool includeAsText = true)
{
var dataObject = new DataObject();
var pathCollection = new StringCollection();
pathCollection.AddRange(paths.ToArray());
dataObject.SetFileDropList(pathCollection);
if (includeAsText)
dataObject.SetText(string.Join(Environment.NewLine, paths));
return dataObject;
}
示例3: cutToolStripMenuItem_Click
private void cutToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
TreeNode tn = folderTreeView.SelectedNode;
if (tn == null) return;
string path = ((FileSystemInfo)tn.Tag).FullName;
StringCollection clip = new StringCollection();
clip.Add(path);
byte[] moveEffect = new byte[] { 2, 0, 0, 0 }; //cut = 0x2000
MemoryStream dropEffect = new MemoryStream();
dropEffect.Write(moveEffect, 0, moveEffect.Length);
DataObject data = new DataObject();
data.SetFileDropList(clip);
data.SetData("Preferred DropEffect", dropEffect);
Clipboard.Clear();
Clipboard.SetDataObject(data, true);
}
catch (Exception ex)
{
Logger.Add(ex.Message, "CodesBrowser|cutToolStripMenuItem_Click");
}
}
示例4: OnDragFile
void OnDragFile(string filename)
{
var dataObject = new DataObject();
var path = Path.Combine(TheState.TransferCenter.IncomingDirectory, filename);
var filePaths = new System.Collections.Specialized.StringCollection();
filePaths.Add(path);
dataObject.SetFileDropList(filePaths);
this.DoDragDrop(dataObject, DragDropEffects.Move | DragDropEffects.Copy);
}
示例5: toolEditCut_Click
private void toolEditCut_Click(object sender, EventArgs e)
{
object copytoclip = dataGridView1.GetClipboardContent();
Int32 selectedRowCount = dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected);
int[] sr;
sr = new Int32[selectedRowCount];
for (int i = 0; i < selectedRowCount; i++)
{
sr[i] = dataGridView1.SelectedRows[i].Index;
}
StringCollection paths = new StringCollection();
for (int p = 0; p < selectedRowCount; p++)
{
paths.Add(gPath.Text + "\\" + dataGridView1.Rows[sr[p]].Cells[0].Value.ToString());
}
byte[] moveEffect = new byte[] { 2, 0, 0, 0 };
MemoryStream dropEffect = new MemoryStream();
dropEffect.Write(moveEffect, 0, moveEffect.Length);
DataObject data = new DataObject();
data.SetFileDropList(paths);
data.SetData("Preferred DropEffect", dropEffect);
Clipboard.Clear();
Clipboard.SetDataObject(data, true);
}
示例6: DoTestMenu
/// <summary>
/// Tests the context menu.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="x">The x.</param>
/// <param name="y">The y.</param>
private void DoTestMenu(ShellItem item, int x, int y)
{
// If we don't have a context menu, we can bail now.
if (TestContextMenu == null)
return;
// Get the interfaces we need to test with.
var shellExtInitInterface = (IShellExtInit) TestContextMenu;
var contextMenuInterface = (IContextMenu) TestContextMenu;
// Try init first.
try
{
// Create the file paths.
var filePaths = new StringCollection {item.Path};
// Create the data object from the file paths.
var dataObject = new DataObject();
dataObject.SetFileDropList(filePaths);
// Get the IUnknown COM interface address. Jesus .NET makes this easy.
var dataObjectInterfacePointer = Marshal.GetIUnknownForObject(dataObject);
// Pass the data to the shell extension, attempt to initialise it.
// We must provide the data object as well as the parent folder PIDL.
shellExtInitInterface.Initialize(item.ParentItem.PIDL, dataObjectInterfacePointer, IntPtr.Zero);
}
catch (Exception)
{
// Not supported for the file
return;
}
// Create a native menu.
var menuHandle = CreatePopupMenu();
// Build the menu.
contextMenuInterface.QueryContextMenu(menuHandle, 0, 0, 1, 0);
// Track the menu.
TrackPopupMenu(menuHandle,
0, x, y, 0, Handle, IntPtr.Zero);
}
示例7: CutFile
private void CutFile()
{
try
{
if (GlobalSetting.IsImageError || !File.Exists(GlobalSetting.ImageList.GetFileName(GlobalSetting.CurrentIndex)))
{
return;
}
}
catch { return; }
GlobalSetting.StringClipboard = new StringCollection();
GlobalSetting.StringClipboard.Add(GlobalSetting.ImageList.GetFileName(GlobalSetting.CurrentIndex));
byte[] moveEffect = new byte[] { 2, 0, 0, 0 };
MemoryStream dropEffect = new MemoryStream();
dropEffect.Write(moveEffect, 0, moveEffect.Length);
DataObject data = new DataObject();
data.SetFileDropList(GlobalSetting.StringClipboard);
data.SetData("Preferred DropEffect", dropEffect);
Clipboard.Clear();
Clipboard.SetDataObject(data, true);
this.DisplayTextMessage(
string.Format(GlobalSetting.LangPack.Items["frmMain._CutFileText"],
GlobalSetting.StringClipboard.Count), 1000);
}
示例8: OnMouseMove
private void OnMouseMove(object sender, MouseEventArgs args)
{
if (!_leftMouseDown)
{
return;
}
if (_isAttached)
{
return;
}
if (_path == null)
{
return;
}
if (Math.Abs(args.X - _startPos.X) < Threshold &&
Math.Abs(args.Y - _startPos.Y) < Threshold)
{
return;
}
var paths = new StringCollection { _path };
var dataObject = new DataObject();
dataObject.SetFileDropList(paths);
dataObject.SetText(_path);
// Allow other classes to check if the DragDrop event was generated by this class
dataObject.SetData(typeof(Format), new Format());
_dragSource.DoDragDrop(dataObject, DragDropEffects.Copy);
_isAttached = true;
}
示例9: CopyCutSelectedToClipboard
/*
* Вирізати в буфер обміну виділені файли, якщо action = 2
* Копіювати в буфер обміну виділені файли, якщо action = 5
*/
public void CopyCutSelectedToClipboard(byte action)
{
if (CurrentField.FieldView.SelectedItems.Count == 0 || (action != 2 && action != 5))
return;
var selectedItems = new System.Collections.Specialized.StringCollection();
for (int i = 0; i < CurrentField.FieldView.SelectedItems.Count; i++)
{
int itemIndex = CurrentField.FieldView.Items.IndexOf(CurrentField.FieldView.SelectedItems[i]);
if (!String.Equals(CurrentField.FieldElementList[itemIndex].Name, ".."))
selectedItems.Add(CurrentField.FieldElementList[itemIndex].Path);
}
byte[] moveEffect = new byte[] { action, 0, 0, 0 };
MemoryStream dropEffect = new MemoryStream();
dropEffect.Write(moveEffect, 0, moveEffect.Length);
DataObject data = new DataObject();
data.SetFileDropList(selectedItems);
data.SetData("Preferred DropEffect", dropEffect);
Clipboard.Clear();
Clipboard.SetDataObject(data, true);
}
示例10: FileStatusListView_MouseMove
void FileStatusListView_MouseMove(object sender, MouseEventArgs e)
{
ListView listView = sender as ListView;
//DRAG
// If the mouse moves outside the rectangle, start the drag.
if (dragBoxFromMouseDown != Rectangle.Empty &&
!dragBoxFromMouseDown.Contains(e.X, e.Y))
{
if (SelectedItems.Any())
{
StringCollection fileList = new StringCollection();
foreach (GitItemStatus item in SelectedItems)
{
string fileName = Path.Combine(Module.WorkingDir, item.Name);
fileList.Add(fileName.Replace('/', '\\'));
}
DataObject obj = new DataObject();
obj.SetFileDropList(fileList);
// Proceed with the drag and drop, passing in the list item.
DoDragDrop(obj, DragDropEffects.Copy);
dragBoxFromMouseDown = Rectangle.Empty;
}
}
//TOOLTIP
if (listView != null)
{
var point = new Point(e.X, e.Y);
var hover = listView.HitTest(point);
if (hover.Item != null)
{
var gitItemStatus = (GitItemStatus)hover.Item.Tag;
string text;
if (gitItemStatus.IsRenamed || gitItemStatus.IsCopied)
text = string.Concat(gitItemStatus.Name, " (", gitItemStatus.OldName, ")");
else
text = gitItemStatus.Name;
float fTextWidth = listView.CreateGraphics().MeasureString(text, listView.Font).Width + 17;
//Use width-itemheight because the icon drawn in front of the text is the itemheight
if (fTextWidth > (FileStatusListView.Width - FileStatusListView.GetItemRect(hover.Item.Index).Height))
{
if (!hover.Item.ToolTipText.Equals(gitItemStatus.ToString()))
hover.Item.ToolTipText = gitItemStatus.ToString();
}
else
hover.Item.ToolTipText = "";
}
}
}
示例11: cut_Click
void cut_Click(object sender, EventArgs e)
{
if (treeView.SelectedNode != null) {
Clipboard.Clear();
CutFileList cutList = new CutFileList();
cutList.Files.Add(((FileTreeNode)treeView.SelectedNode).File.Info.FullName);
DataObject o = new DataObject();
o.SetFileDropList(cutList.Files);
o.SetData(typeof(CutFileList).ToString(), cutList);
Clipboard.SetDataObject(o);
}
}
示例12: treeView_MouseMove
private void treeView_MouseMove(object sender, MouseEventArgs e)
{
if (draggedNode != null && (e.Button & MouseButtons.Left) != 0) {
if (!dragRect.Contains(e.Location)) {
StringCollection files = new StringCollection();
files.Add(draggedNode.File.Info.FullName);
DataObject o = new DataObject();
o.SetFileDropList(files);
draggedNode = null;
dragRect = Rectangle.Empty;
DoDragDrop(o, DragDropEffects.Copy | DragDropEffects.Move);
}
}
}
示例13: Unstaged_MouseMove
void Unstaged_MouseMove(object sender, MouseEventArgs e)
{
//DRAG
// If the mouse moves outside the rectangle, start the drag.
if (dragBoxFromMouseDown != Rectangle.Empty &&
!dragBoxFromMouseDown.Contains(e.X, e.Y))
{
if (Unstaged.SelectedRows.Count > 0)
{
StringCollection fileList = new StringCollection();
foreach (DataGridViewRow row in Unstaged.SelectedRows)
{
GitItemStatus item = (GitItemStatus)row.DataBoundItem;
string fileName = Settings.WorkingDir + item.Name;
fileList.Add(fileName.Replace('/', '\\'));
}
DataObject obj = new DataObject();
obj.SetFileDropList(fileList);
// Proceed with the drag and drop, passing in the list item.
DragDropEffects dropEffect = Unstaged.DoDragDrop(
obj,
DragDropEffects.Copy);
dragBoxFromMouseDown = Rectangle.Empty;
}
}
//TOOLTIP
if (sender is DataGridView)
{
DataGridView dataGridView = (DataGridView)sender;
int hoverIndex = dataGridView.HitTest(e.X, e.Y).RowIndex;
if (e.X < dataGridView.Location.X + nameDataGridViewTextBoxColumn1.Width &&
hoverIndex >= 0 && hoverIndex < dataGridView.Rows.Count)
{
string text = ((GitItemStatus)dataGridView.Rows[hoverIndex].DataBoundItem).Name;
float fTextWidth = dataGridView.CreateGraphics().MeasureString(text, dataGridView.Font).Width;
if (fTextWidth > nameDataGridViewTextBoxColumn1.Width)
fileTooltip.SetToolTip(dataGridView, text);
else
fileTooltip.RemoveAll();
}
else
{
fileTooltip.RemoveAll();
}
}
}
示例14: elvw_Images_ItemDrag
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void elvw_Images_ItemDrag(object sender, ItemDragEventArgs e)
{
if ((e.Button == MouseButtons.Left) && (elvw_Images.SelectedItems.Count > 0))
{
System.Collections.Specialized.StringCollection oPaths =
new System.Collections.Specialized.StringCollection();
foreach (ListViewItem oItem in elvw_Images.SelectedItems)
{
// Add the name of the item if it isn't empty or null to path list
if (!string.IsNullOrEmpty(oItem.Name))
{
if (File.Exists(oItem.Name))
oPaths.Add(oItem.Name);
}
}
if (oPaths.Count > 0)
{
// Create a data object and add the path collection to the file drop list.
DataObject oData = new DataObject();
oData.SetFileDropList(oPaths);
// Perform the drag and drop, with the file path collection and move drag and drop effect.
elvw_Images.DoDragDrop(oData, DragDropEffects.Move);
}
}
}
示例15: lvFiles_ItemDrag
private void lvFiles_ItemDrag(object sender, ItemDragEventArgs e)
{
if (lvFiles.SelectedItems.Count != 1)
{
return;
}
var fe = (BSAFileEntry) lvFiles.SelectedItems[0].Tag;
var path = Path.Combine(Program.CreateTempDirectory(), fe.FileName);
fe.Extract(path, false, br, ContainsFileNameBlobs);
var obj = new DataObject();
var sc = new StringCollection();
sc.Add(path);
obj.SetFileDropList(sc);
lvFiles.DoDragDrop(obj, DragDropEffects.Move);
}