C#支持文件拖拽
2024-10-14 04:29:50
- private void listBox1_DragEnter(object sender, DragEventArgs e)
- {
- if (e.Data.GetDataPresent(DataFormats.FileDrop))
- {
- e.Effect = DragDropEffects.Copy;
- }
- else
- {
- e.Effect = DragDropEffects.None;
- }
- }
- private void listBox1_DragDrop(object sender, DragEventArgs e)
- {
- string[] test = (string[])e.Data.GetData(DataFormats.FileDrop, false);
- //MessageBox.Show(test[0].ToString());
- Tps1.Clear();
- listBox1.Items.Clear();
- try
- {
- if (test[0].ToString().Contains(".txt"))
- {
- StreamReader sr1 = new StreamReader(test[0].ToString(), Encoding.UTF8);
- string line1;
- while ((line1 = sr1.ReadLine()) != null)
- {
- if (line1.Trim() == "")
- continue;
- Tps1.Add(line1);
- listBox1.Items.Add(line1);
- }
- sr1.Close();
- sr1.Dispose();
- }
- }
- catch { MessageBox.Show("文件不能识别!"); }
- }
最新文章
- Servlet基础(三) Servlet的多线程同步问题
- [转]关于信息安全认证CISP与CISSP的对比及分析
- ArcGIS发布地图服务
- POJ2406 Power Strings KMP算法
- Android中UI线程与后台线程交互设计的5种方法
- 监控mysql执行的sql语句
- String 的intern() 方法说明
- MessageBox, MessageBoxBurttons, MessageBoxIcon 详细解析
- iOS 9界面适配利器:详解Xcode 7的新特性UIStackView
- [Lua]Mac系统上安装Lua环境
- windows系统下安装composer
- oracle 权限
- JavaScript代码规范
- MySQL 5.7自定义安装图文详解
- 安装Python 3.6 在Ubuntu 16.04 LTS 版本
- C#泛型约束where T : class 解释
- LED类代码
- JavaScript -- Window-Resize
- Poly2Tri介绍[转]
- Nagios自定义扩展