【平移】
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 btnTraslate_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(200,0); graphics.RotateTransform(90); // 蓝色笔 pen.Color = Color.Blue; // 用蓝色笔重新画平移之后的矩形 graphics.DrawRectangle(pen, rect); graphics.Dispose(); pen.Dispose(); }
坐标原点为矩形的左上点。
时间: 2024-10-20 05:07:18