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

    上显示效果

  • 相关阅读:
    hibernate关联关系
    数据结构之二叉树java实现
    队列java实现
    栈java实现
    原生JS结合cookie实现商品评分组件
    JAVA学习第一阶段(2)
    JAVA学习第一阶段(1)
    如何修改hosts并保存
    运行Apache时出现the requested operation has failed
    实现一元多项式
  • 原文地址:https://www.cnblogs.com/mamiyiya777/p/6114421.html
Copyright © 2020-2023  润新知