在运行时在 winform 内拖动图片框 [英] dragging picturebox inside winform on runtime
本文介绍了在运行时在 winform 内拖动图片框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要能够在 vb.net 中将带有图像的图片框拖放到我的 winform 周围.
i need to be able to drag and drop my picturebox with an image in it around my winform in vb.net.
推荐答案
这是在 C# 中,但应该很容易在 VB.Net 中复制.
This is in C#, but should be easy enough to replicate in VB.Net.
private int currentX, currentY;
private bool isDragging = false;
private void myPictureBox_MouseDown(object sender, MouseEventArgs e)
{
isDragging = true;
currentX = e.X;
currentY = e.Y;
}
private void myPictureBox_MouseMove(object sender, MouseEventArgs e)
{
if (isDragging)
{
myPictureBox.Top = myPictureBox.Top + (e.Y - currentY);
myPictureBox.Left = myPictureBox.Left + (e.X - currentX);
}
}
private void myPictureBox_MouseUp(object sender, MouseEventArgs e)
{
isDragging = false;
}
这篇关于在运行时在 winform 内拖动图片框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文