不错呦!smile@林凯西,确保“准备文件”中的几个文件都有安装,S...您好,看了您这篇帖子觉得很有帮助。但是有个问题想请...我的修改过了怎么还被恶意注册呢 @jjjjiiii 用PJ快9年了,主要是A...PJ3啊,貌似很少有人用PJ了,现在不是WP就是z...@332347365,我当时接入时错误码没有-10...楼主,ChkValue值应为-103是什么意思呢?...大哥 你最近能看到我发的信息,请跟我联系,我有个制...
HOW TO:从资源管理器中拖放文件到控件
编辑:dnawo 日期:2009-06-09
当然,这里所谓的文件是指完整的文件名称,至于文件的内容,须按实际情况进一步的操作。
我这里的控件为一个ListBox。代码如下:
重写这个HOW TO,主要的是看到有人用API实现,代码如下:
VB.NET:
C#:
我这里的控件为一个ListBox。代码如下:
复制内容到剪贴板
程序代码

Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ListBox1.AllowDrop = True
End Sub
Private Sub ListBox1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragEnter
Dim o As Object = e.Data.GetData(DataFormats.FileDrop)
If Not o Is Nothing Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub ListBox1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragDrop
Dim FileNames As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
Me.ListBox1.Items.AddRange(FileNames)
End Sub
End Class
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ListBox1.AllowDrop = True
End Sub
Private Sub ListBox1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragEnter
Dim o As Object = e.Data.GetData(DataFormats.FileDrop)
If Not o Is Nothing Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub ListBox1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragDrop
Dim FileNames As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
Me.ListBox1.Items.AddRange(FileNames)
End Sub
End Class
重写这个HOW TO,主要的是看到有人用API实现,代码如下:
VB.NET:
复制内容到剪贴板
程序代码

Public Class Form1
Private Const WM_DropFILES As Integer = 563
Private Declare Function DragAcceptFiles Lib "shell32.dll" (ByVal hwnd As IntPtr, ByVal accept As Boolean) As Long
Private Declare Function DragQueryFile Lib "shell32.dll" (ByVal hDrop As IntPtr, ByVal file As Integer, ByVal fileName As System.Text.StringBuilder, ByVal size As Int32) As Int32
Private Declare Sub DragFinish Lib "Shell32.dll" (ByVal hDrop As IntPtr)
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_DropFILES Then
Dim iNumOfFiles As Int32 = DragQueryFile(m.WParam, &HFFFFFFFF, Nothing, 0)
Dim iPnt As Int32
For iPnt = 0 To iNumOfFiles - 1
Dim sb As New System.Text.StringBuilder(256)
Dim iRet As Int32 = DragQueryFile(m.WParam, iPnt, sb, sb.Capacity)
ListBox1.Items.Add(sb.ToString)
Next
DragFinish(m.WParam)
Else
MyBase.WndProc(m)
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
DragAcceptFiles(ListBox1.Handle, True)
End Sub
End Class
Private Const WM_DropFILES As Integer = 563
Private Declare Function DragAcceptFiles Lib "shell32.dll" (ByVal hwnd As IntPtr, ByVal accept As Boolean) As Long
Private Declare Function DragQueryFile Lib "shell32.dll" (ByVal hDrop As IntPtr, ByVal file As Integer, ByVal fileName As System.Text.StringBuilder, ByVal size As Int32) As Int32
Private Declare Sub DragFinish Lib "Shell32.dll" (ByVal hDrop As IntPtr)
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_DropFILES Then
Dim iNumOfFiles As Int32 = DragQueryFile(m.WParam, &HFFFFFFFF, Nothing, 0)
Dim iPnt As Int32
For iPnt = 0 To iNumOfFiles - 1
Dim sb As New System.Text.StringBuilder(256)
Dim iRet As Int32 = DragQueryFile(m.WParam, iPnt, sb, sb.Capacity)
ListBox1.Items.Add(sb.ToString)
Next
DragFinish(m.WParam)
Else
MyBase.WndProc(m)
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
DragAcceptFiles(ListBox1.Handle, True)
End Sub
End Class
C#:
复制内容到剪贴板
程序代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
const int WM_DropFILES = 563;
[DllImport("shell32.dll")]
private static extern long DragAcceptFiles(IntPtr hwnd, bool accept);
[DllImport("shell32.dll")]
private static extern int DragQueryFile(IntPtr hDrop, int file, StringBuilder fileName, int size);
[DllImport("shell32.dll")]
private static extern void DragFinish(IntPtr hDrop);
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_DropFILES)
{
int iNumOfFiles = DragQueryFile(m.WParam, -1, null, 0);
int iPnt;
for (iPnt = 0; iPnt < iNumOfFiles; iPnt++)
{
StringBuilder sb = new StringBuilder(256);
int iRet = DragQueryFile(m.WParam, iPnt, sb, sb.Capacity);
listBox1.Items.Add(sb.ToString());
}
DragFinish(m.WParam);
}
else
{
base.WndProc(ref m);
}
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DragAcceptFiles(listBox1.Handle, true);
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
const int WM_DropFILES = 563;
[DllImport("shell32.dll")]
private static extern long DragAcceptFiles(IntPtr hwnd, bool accept);
[DllImport("shell32.dll")]
private static extern int DragQueryFile(IntPtr hDrop, int file, StringBuilder fileName, int size);
[DllImport("shell32.dll")]
private static extern void DragFinish(IntPtr hDrop);
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_DropFILES)
{
int iNumOfFiles = DragQueryFile(m.WParam, -1, null, 0);
int iPnt;
for (iPnt = 0; iPnt < iNumOfFiles; iPnt++)
{
StringBuilder sb = new StringBuilder(256);
int iRet = DragQueryFile(m.WParam, iPnt, sb, sb.Capacity);
listBox1.Items.Add(sb.ToString());
}
DragFinish(m.WParam);
}
else
{
base.WndProc(ref m);
}
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DragAcceptFiles(listBox1.Handle, true);
}
}
}
评论: 0 | 引用: 0 | 查看次数: 4128
发表评论
请登录后再发表评论!