public partial class Img : Form
{
public Img(string file)
{
InitializeComponent();
maxImg.ImageLocation = file;
this.MouseWheel += Img_MouseWheel;
}
private void Img_MouseWheel(object sender, MouseEventArgs e)
{
if (e.Delta > 0) //放大图片
{
maxImg.Size = new Size(maxImg.Width + 50, maxImg.Height + 50);
}
else
{ //缩小图片
maxImg.Size = new Size(maxImg.Width - 50, maxImg.Height - 50);
}
//设置图片在窗体居中
maxImg.Location = new Point((this.Width - maxImg.Width) / 2, (this.Height - maxImg.Height) / 2);
}
private void maxImg_Click(object sender, EventArgs e)
{
Bitmap img = new Bitmap(maxImg.Image);//得到图片框中的图片
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
maxImg.Image = img;
}
private void Img_Load(object sender, EventArgs e)
{
maxImg.Location = new Point((this.Width - maxImg.Width) / 2, (this.Height - maxImg.Height) / 2);
}
}