C#我图片都大小一致92*56,加载的时候按自动排好不重叠,下面的代码要怎样改
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
namespace DragImages
{
public partial class Form1 : Form
{
public class ImgInfo
{
private Image m_Img;
private Point m_Pot;
public Image Img
{
get { return m_Img; }
}
public Point Pot
{
get { return m_Pot; }
set { m_Pot = value; }
}
public ImgInfo(Image img)
{
m_Img = img;
}
}
private List<ImgInfo> imgList;
private Point lastPoint;
private Point lastMsPoint;
private ImgInfo curImgInfo;
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.imgList = new List<ImgInfo>();
this.DoubleBuffered = true;
}
protected override void OnDoubleClick(EventArgs e)
{
base.OnDoubleClick(e);
OpenFileDialog of = new OpenFileDialog();
of.Multiselect = true;
of.Filter = "jpg文件;asdfsad;asdfsa|*.jpg|bmp文件|*.bmp|gif文件|*.gif";
if (of.ShowDialog(this) == DialogResult.OK)
{
imgList.Clear();
for (int i = 0; i < of.FileNames.Length; i++)
{
Image img = Image.FromFile(of.FileNames[i]);
imgList.Add(new ImgInfo(img));
}
}
if (this.imgList.Count > 0)
{
this.Invalidate();
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Point m_beginPoint = Point.Empty;
for (int i = 0; i < this.imgList.Count; i++)
{
Rectangle rect = new Rectangle(this.imgList[i].Pot, this.imgList[i].Img.Size);
e.Graphics.DrawImage(this.imgList[i].Img,rect);
Point m_endPoint = new Point(rect.Left / 2 + rect.Right / 2, rect.Top / 2 + rect.Bottom / 2);
if (m_beginPoint != Point.Empty)
{
e.Graphics.DrawLine(SystemPens.ControlDarkDark, m_beginPoint, m_endPoint);
}
m_beginPoint = m_endPoint;
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
this.lastMsPoint = e.Location;
for (int i = this.imgList.Count - 1; i > -1; i--)
{
ImgInfo info = this.imgList[i];
Rectangle rect = new Rectangle(info.Pot, info.Img.Size);
if (rect.Contains(e.Location))
{
this.curImgInfo = info;
this.lastPoint = info.Pot;
return;
}
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (this.Capture && this.curImgInfo != null)
{
this.curImgInfo.Pot = new Point(this.lastPoint.X + e.X - this.lastMsPoint.X, this.lastPoint.Y + e.Y - this.lastMsPoint.Y);
this.Invalidate();
}
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
this.curImgInfo = null;
}
}
}