如何拖放图像? C# [英] how to drag and drop an image? C#
本文介绍了如何拖放图像? C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为游戏制作一个简单的2D地图制作器.只需用户单击一个将显示打开文件"对话框的按钮.用户选择一个文件并加载到PictureBox中.然后,如果用户要将其添加到游戏世界(面板)中,则他/她单击添加按钮,面板将加载图片.我遇到的麻烦是能够在该面板中拖放图像.感谢您的帮助.
Windows 7 Visual C#Winform
谢谢,
Hi, I am making a simple 2D map maker for games. Simply the user clicks on a button that will show a openfiledialog. The user chooses a file and is loaded in a PictureBox. Then if the user wants to add it to the game world(panel) he/she clicks on the add button and the panel will load the picture. What I am having trouble with is being able to drag and drop the image within that panel. I will appreciate your help.
windows 7 visual C# winform
thanks,
推荐答案
msdn资源:
http://msdn.microsoft.com/en-us/library/ms171546.aspx
和
http://msdn.microsoft.com/en-us/library/za0zx9y0.aspx
msdn resources:
http://msdn.microsoft.com/en-us/library/ms171546.aspx
and
http://msdn.microsoft.com/en-us/library/za0zx9y0.aspx
您好,
我认为这可以帮助您:
Hello,
I think this can help:
private bool isPictureReadyToDrag;
private void SetPosition()
{
MyPictureBox.Location = new Point(MousePosition.X - this.Left - MyPictureBox.Width / 2, MousePosition.Y - this.Top - MyPictureBox.Height);
}
private void MyPictureBox_MouseMove(object sender, MouseEventArgs e)
{
if (isPictureReadyToDrag)
SetPosition();
}
private void MyPictureBox_MouseUp(object sender, MouseEventArgs e)
{
isPictureReadyToDrag = false;
}
private void MyPictureBox_MouseDown(object sender, MouseEventArgs e)
{
isPictureReadyToDrag = true;
SetPosition();
}
这篇关于如何拖放图像? C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文