C# 画图

 

 private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //Graphics g = e.Graphics;//创建画板,这里的画板由from提供
            //Pen p = new Pen(Color.Blue,2); //定义了一个蓝色的宽度为2的画笔
            //g.DrawLine(p,10,10,100,100); //在画板上画直线,起始坐标是(10,10),终点坐标为(100,100)
            //g.DrawRectangle(p,10,10,100,100); //在画板上画矩形,起始坐标为(10,10),宽为100,高为100
            //g.DrawEllipse(p,10,10,100,100); //在画板上画椭圆,起始坐标(10,10)宽高为100

            //Pen p = new Pen(Color.Blue,5);
            //Graphics g = this.CreateGraphics();
            //p.DashStyle = DashStyle.Dot;  //画虚线
            //g.DrawLine(p,10,10,200,10);
            自定义虚线
            //p.DashPattern = new float[] { 2,1}; //设置短划线和空白部分的数组
            //g.DrawLine(p,10,20,200,20);
            画箭头,只对不封闭曲线有用
            //p.DashStyle = DashStyle.Solid;//实线
            //p.EndCap = LineCap.ArrowAnchor; //定义线尾的样式为箭头
            //g.DrawLine(p,10,30,200,30);
            //g.Dispose();
            //p.Dispose();


            //Graphics g = this.CreateGraphics();
            //Rectangle rect = new Rectangle(10,10,50,50);
            //SolidBrush b1 = new SolidBrush(Color.Blue); //定义单色画刷
            //g.FillRectangle(b1,rect); //填充这个矩形
            //g.DrawString("字符串",new Font("宋体",10),b1,new PointF (90,10));
            用图片填充
            //TextureBrush b2 = new TextureBrush(Image.FromFile(@"C:\Documents and Settings\Lenovo\桌面\ggg\www\www\IMG0801175000.jpg"));
            //rect.Location = new Point(10,70);
            //rect.Width = 200;
            //rect.Height = 200;
            //g.FillRectangle(b2,rect);
            用渐变色填充
            //rect.Location = new Point(10,290);
            //LinearGradientBrush b3 = new LinearGradientBrush(rect,Color.Yellow,Color.Black,LinearGradientMode.Horizontal);
            //g.FillRectangle(b3,rect);


            Graphics g = this.CreateGraphics();
            //单色填充
            SolidBrush b1 = new SolidBrush(Color.Blue); //定义单色画刷
            Pen p = new Pen(Color.Blue,1);
            //转变坐标轴角度
            for (int i = 0; i < 90; i++)
            {
                g.RotateTransform(i);//每旋转一度就画一条线
                g.DrawLine(p,0,0,100,0);
                g.ResetTransform();//恢复坐标轴坐标
            }
            //平移坐标轴
            g.TranslateTransform(100,100);
            g.DrawLine(p,0,0,100,0);
            g.ResetTransform();
            //先平移到指定坐标,然后进行旋转
            g.TranslateTransform(100,200);
            for (int i = 0; i < 8; i++)
            {
                g.RotateTransform(45);
                g.DrawLine(p,0,0,100,0);
            }
            g.Dispose();
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值