点睛:可以进行多次旋转和平移,也就是平移以后再平移,旋转以后再旋转,有时候一次达不到要求,如果你想一次调整完美的话很麻烦,所以最好多次,上代码
private void btnTranslate_Click(object sender, EventArgs e)
{
Graphics graphics = this.CreateGraphics();
// 红色笔
Pen pen = new Pen(Color.Red, );
Rectangle rect = new Rectangle(, , , );
// 用红色笔画矩形
graphics.DrawRectangle(pen, rect);
// 向左平移100向下平移50
graphics.TranslateTransform(, );
// 蓝色笔
pen.Color = Color.Blue;
// 用蓝色笔重新画平移之后的矩形
graphics.DrawRectangle(pen, rect);
graphics.Dispose();
pen.Dispose(); } private void btnScale_Click(object sender, EventArgs e)
{
Graphics graphics = this.CreateGraphics();
// 红色笔
Pen pen = new Pen(Color.Red, );
Rectangle rect = new Rectangle(, , , );
// 用红色笔画矩形
graphics.DrawRectangle(pen, rect);
graphics.ScaleTransform(0.5f, );
// 蓝色笔
pen.Color = Color.Blue;
// 用蓝色笔重新画平移之后的矩形
graphics.DrawRectangle(pen, rect);
graphics.Dispose();
pen.Dispose(); } private void btnTranslate1_Click(object sender, EventArgs e)
{
Graphics graphics = this.CreateGraphics();
// 红色笔
Pen pen = new Pen(Color.Red, );
Rectangle rect = new Rectangle(, , , );
// 用红色笔画矩形
graphics.DrawRectangle(pen, rect);
graphics.TranslateTransform( , );
graphics.RotateTransform();
// 蓝色笔
pen.Color = Color.Blue;
// 用蓝色笔重新画平移之后的矩形
graphics.DrawRectangle(pen, rect);
graphics.Dispose();
pen.Dispose(); }
上显示效果