今天在做textBox拖曳的功能,学到一点点

            textBoxCmdName.AllowDrop = true;
            textBoxCmdName.DragDrop += new DragEventHandler(txt_ObjDragDrop);
            textBoxCmdName.DragEnter += new DragEventHandler(txt_ObjDragEnter);


 

        private static void txt_ObjDragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Link;
        }

        private static void txt_ObjDragDrop(object sender, DragEventArgs e)
        {
            try
            {
                string FileName = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();//文件
                System.Diagnostics.Process.Start("notepad", FileName);
                //((TextBox)sender).Text = File.ReadAllText(FileName, Encoding.Default);
            }
            catch (Exception er)
            {
                Console.Write(er.Message);
            }
        }


 

 

posted @ 2012-08-20 15:50  真爱无限  阅读(175)  评论(0编辑  收藏  举报