夏456 2023-03-16 15:02 采纳率: 85.7%
浏览 60
已结题

c#中如何将listview中的项拖拽显示到picturebox背景中?

c#中如何将listview中的项拖拽显示到picturebox背景中?

img

picturebox无法接收来自listview的字符并且显示字符?想要接收的是listview如图所示的项,然后通过拖拽到picturebox的背景上。本人刚接触c#时间不长,找了一天资料都没有解决,谢谢大家的帮忙。


 private void listView1_ItemDrag(object sender, ItemDragEventArgs e)
        {
            //if (e.Button == MouseButtons.Right) return;
            //int nTotalSelected = listView1.SelectedIndices.Count;

            // DoDragDrop(e.Item.ToString(), DragDropEffects.Copy);
        }

        private void listView1_MouseDown(object sender, MouseEventArgs e)
        {
            if (listView1.SelectedItems == null)
                return;
             ListViewItem selectedItem = listView1.SelectedItems[0];
            listView1.DoDragDrop(listView1.SelectedItems, DragDropEffects.Copy);

        }

        private void listView1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(string)))
            {
                e.Effect = DragDropEffects.Copy;
            }
            { e.Effect = DragDropEffects.None; }
        }
        private void Form1_Load(object sender, EventArgs e)
        {        
        }
        //判断是不是可以接收的类型
        private void pictureBox1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(string)))
            {
                e.Effect = DragDropEffects.Copy;
            }
            { e.Effect = DragDropEffects.None; }
        }

        private void pictureBox1_DragDrop(object sender, DragEventArgs e)
        {
            //把数据显示在picture
            string data = (string)e.Data.GetData(typeof(string));
            Graphics g = pictureBox1.CreateGraphics();
            g.DrawString(data, new Font("Arial", 12), Brushes.Black, 10, 10);

        }
  • 写回答

3条回答 默认 最新

  • 於黾 2023-03-16 15:21
    关注

    listView1.SelectedItems是个集合,不是字符串呀

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 3月17日
  • 已采纳回答 3月17日
  • 修改了问题 3月16日
  • 修改了问题 3月16日
  • 展开全部

悬赏问题

  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上