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