如果将listview中的值比如111拖拽到picturebox上并且使用drawstring的方法显示出来后,如何在picturebox上继续拖拽移动111,代码该如何实现
时间: 2023-05-22 19:02:21 浏览: 102
您可以使用鼠标事件来实现在picturebox上拖拽移动111。具体实现方法如下:
1. 在picturebox的MouseDown事件中记录鼠标按下时的坐标和拖拽的值(111)。
2. 在picturebox的MouseMove事件中判断鼠标是否按下,如果按下则计算鼠标移动的距离,并将拖拽的值(111)绘制到新的位置上。
3. 在picturebox的MouseUp事件中清除拖拽的值(111)。
以下是示例代码:
private int dragValue;
private Point dragStart;
private void listView1_ItemDrag(object sender, ItemDragEventArgs e)
{
dragValue = (int)listView1.SelectedItems[0].Tag;
listView1.DoDragDrop(dragValue, DragDropEffects.Move);
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
dragStart = e.Location;
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
int dx = e.X - dragStart.X;
int dy = e.Y - dragStart.Y;
Graphics g = pictureBox1.CreateGraphics();
g.DrawString(dragValue.ToString(), Font, Brushes.Black, e.X, e.Y);
dragStart = e.Location;
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
dragValue = 0;
}
阅读全文
相关推荐


















