c#中如何将listview中的项拖拽显示到picturebox背景中?
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);
}