zoukankan      html  css  js  c++  java
  • C#-支持文件拖拽

            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("文件不能识别!"); }
            }

  • 相关阅读:
    css3转换
    JavaScript函数
    JavaScript数组
    JavaScript流程控制
    JavaScript数据类型、运算
    css3响应布局
    css3渐变、背景、过渡、分页
    css3初识
    CSS3选择器
    H5拖拽、绘画、web存储
  • 原文地址:https://www.cnblogs.com/csnd/p/12062174.html
Copyright © 2011-2022 走看看