| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 603 人关注过本帖
标题:C#中让ListBox支持文件路径的拖放
只看楼主 加入收藏
够Le累Le
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2009-9-7
收藏
 问题点数:0 回复次数:0 
C#中让ListBox支持文件路径的拖放
有时,我们程序,需要加载一个文件列表,这个列表,通常用ListBox来存放,为了方便操作,让listBox支持拖放入文件的路径,是个非常好的功能,在.NET里面实现这个功能,是非常方便,只需要3个步骤:
将 ListBox 的 AllowDrop 属性设为 true
在 ListBox 的 DragOver 和 DragEnter 事件中处理
void ListBox1DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
void ListBox1DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
上面的 e.Effect 可以根据实际情况,调节不同的值,不过,如果不确定,就用默认的All
3. 处理拖放事件
void ListBox1DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
{
String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
foreach (String s in files)
{
(sender as ListBox).Items.Add(s);
}
}
C#中让ListBox支持文件路径的拖放 - 【源码编程】 - 渲染吧精英论坛,推荐!http://www.
搜索更多相关主题的帖子: ListBox 路径 文件 
2009-09-07 13:40
快速回复:C#中让ListBox支持文件路径的拖放
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019876 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved