明白了,看源码:
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace fangda
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
int a, b, c, d;
Rectangle r=new Rectangle();
Graphics g;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
a = e.X;
b = e.Y;
this.pictureBox2.Image = null;
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
Image i=this.pictureBox1.Image;
c = e.X;
d = e.Y;
r.Location = new Point(a, b);
r.Width = c - a;
r.Height = d - b;
Rectangle g1=new Rectangle();
g1.Location = new Point(0,0);
g1.Width = r.Height * 2;
g1.Height = r.Height * 2;
g.DrawImage(i, g1, r, GraphicsUnit.Pixel);
}
private void Form1_Load(object sender, EventArgs e)
{
g = this.pictureBox2.CreateGraphics();
}
}
}