开发环境 Vs2008 c#
我实现这样一个操作:
用一个SplitContainer来放置一个PictureBox和ListView
在ListView中显示的是文件名称列表,让后我在该列表中拖动文件名称到PictureBox中进行显示。
--以下代码为PictureBox
            ScenePictureBox.Dock = DockStyle.Fill;
            ScenePictureBox.AllowDrop = true;
            ScenePictureBox.BackColor = Color.Transparent;
            ScenePictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
            ScenePictureBox.Image = Image.FromFile(clsEnmt.objSystemInfo.ResImg + objRes.objPreResolut.FUnitPicture);
            ScenePictureBox.DragEnter += new DragEventHandler(ScenePictureBox_DragEnter);
            ScenePictureBox.DragDrop += new DragEventHandler(ScenePictureBox_DragDrop);
            ScenePictureBox.DragOver += new DragEventHandler(ScenePictureBox_DragOver);
--以下代码为ListView
            SceneListView.Dock = DockStyle.Fill;
            SceneListView.AllowDrop = true;  
            SceneListView.ItemDrag += new ItemDragEventHandler(SceneListView_ItemDrag);
--事件1.
        private  void SceneListView_ItemDrag(object sender, ItemDragEventArgs e)
        {
           // this.Text = e.Item.ToString(); 
             ListView.SelectedListViewItemCollection cllSelItemTemp = SceneListView.SelectedItems;
            ListViewItem objTemp=cllSelItemTemp[0];
            SceneListView.DoDragDrop(objTemp.SubItems[2].Text, DragDropEffects.Copy | DragDropEffects.Move);
        }这是我发现PictureBox禁止我拖入ListViewItem对象上的文件名称。

解决方案 »

  1.   

     void ScenePictureBox_DragDrop(object sender, DragEventArgs e)
            {
                this.Text = e.Data.GetData("Text").ToString();
            }        void ScenePictureBox_DragEnter(object sender, DragEventArgs e)
            {
                if (e.Data.GetData("Text") != null)
                {
                    e.Effect = DragDropEffects.All;
                } 
            }这样看看.
      

  2.   

    ScenePictureBox.AllowDrop = true;
      

  3.   


    ScenePictureBox.AllowDrop = true;
    ScenePictureBox.DragDrop += new DragEventHandler(ScenePictureBox_DragDrop);
    ScenePictureBox.DragOver += new DragEventHandler(ScenePictureBox_DragOver);void ScenePictureBox_DragOver(object sender, DragEventArgs e)
    {
        //throw new Exception("The method or operation is not implemented.");
        e.Effect = DragDropEffects.All;
    }void ScenePictureBox_DragDrop(object sender, DragEventArgs e)
    {
        //throw new Exception("The method or operation is not implemented.");
        if (e.Data.GetDataPresent(typeof(string)))
        {
            string filename = (string)e.Data.GetData(typeof(string));
            Debug.WriteLine(filename );
        }
    }void SceneListView_ItemDrag(object sender, ItemDragEventArgs e)
    {
        //throw new Exception("The method or operation is not implemented.");
        ListViewItem lvi = e.Item as ListViewItem;
        string filename = lvi.SubItems[2].Text;
        //Debug.WriteLine(filename);    SceneListView.DoDragDrop(filename, DragDropEffects.Copy | DragDropEffects.Move);
    }