[C#] Graphics平移缩放旋转

【平移】

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();
        }

[C#] Graphics平移缩放旋转

【缩放】

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();
        }

[C#] Graphics平移缩放旋转

宽缩小一半,高放大一倍

【旋转】

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();
        }

[C#] Graphics平移缩放旋转


[C#] Graphics平移缩放旋转

坐标原点为矩形的左上点。






[C#] Graphics平移缩放旋转

上一篇:window7 多用户远程登录配置过程


下一篇:EditorWindow中手动控制焦点