【发布时间】:2015-12-31 11:12:00
【问题描述】:
我对 C# 还很陌生,并且在我想做的一个小项目上遇到了很多困难。
我正忙于制作拼贴画之类的东西我的拼贴画。
我想展示一张图片,但我不能发布低于 10 分的图片。但是在这里寻找image:
我无法让它工作。我在网上寻求帮助,但我真的找不到我要找的东西。我找到的东西太不清楚了,我很难理解。
这是我到目前为止的代码从左到右拖放,但它不起作用;
private void pictureBox1_DragEnter(object sender, DragEventArgs e)
{
int len = e.Data.GetFormats().Length - 1;
int i;
for (i = 0; i <= len; i++)
{
if (e.Data.GetFormats()[i].Equals("System.Windows.Forms.ListView+SelectedListViewItemCollection"))
{
//The data from the drag source is moved to the target.
e.Effect = DragDropEffects.Move;
}
}
}
private void pictureBox1_DragDrop(object sender, DragEventArgs e)
{
//Return if the items are not selected in the ListView control.
if (listView1.SelectedItems.Count == 0)
{
return;
}
ListViewItem dragitem = listView1.SelectedItems[0];
pictureBox2.Image = imageList1.Images[dragitem.ImageIndex];
listView1.Items.Remove(dragitem);
}
private void listView1_MouseDown(object sender, MouseEventArgs e)
{
listView1.DoDragDrop(listView1.SelectedItems, DragDropEffects.Move);
}
在我可以将图像添加到左侧之后,如何使用鼠标坐标拖动和移动它们?
任何帮助将不胜感激。 一切都在 Windows 窗体中使用 C# 完成。
【问题讨论】:
-
如果您想将图像放入特定的插槽以形成拼贴,那么我可以帮助您。我的意思是,您可以将正确的图片框拆分为 9 个(或其他)图片框。然后,您可以编写代码以使图像落入插槽,从而形成图像。另一方面,如果你想要重叠的图像可以放在图片框内的任何地方,那就更难了。
-
@FarhanAnam 好的,我认为这将是一个很好的开始。
-
Farhan 解决了第一个也是最重要的问题:您希望图像重叠(如拼贴)还是不重叠(如图片库)?您需要对此做出决定,然后我们才能就如何以最佳方式进行提供建议。第二个问题是目标是否应在放置后可编辑/可移动?
-
好吧,图像必须彼此相对,彼此之间没有任何间隙。其目的主要是为了将航拍照片拼接在一起,使其看起来像一张地图。这意味着它们也必须以正确的顺序组织起来。通过使图像重叠成为可能,之后将提高图像的精度,因为用户可以手动微调所有内容。
标签: c# winforms listview drag-and-drop picturebox