• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C#画图(1)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

protected override void OnPaint(PaintEventArgs paintEvnt)
        {
            //获取画板
            Graphics gfx = paintEvnt.Graphics;
            // 构造画笔
            Pen myPen = new Pen(Color.Black);
            // 画线
            for (int i = 20; i < 250; i = i + 10)
            {
                gfx.DrawLine(myPen, 20, i, 270, i);
            }
        }

垂直画一遍,画出方格:

protected override void OnPaint(PaintEventArgs paintEvnt)
        {
            // Get the graphics object
            Graphics gfx = paintEvnt.Graphics;
            // Create a new pen that we shall use for drawing the line
            Pen myPen = new Pen(Color.Black);
            // Loop and create a horizontal line 10 pixels below the last one
            for(int i = 20; i <= 250; i = i + 10)
            {
                gfx.DrawLine(myPen, 20, i, 270, i);
            }
            // Loop and create a vertical line 10 pixels next to the last one
            for(int x = 20; x < 280; x = x + 10)
            {
                gfx.DrawLine(myPen, x, 20, x, 250);
            }
        }
画方框:

protected override void OnPaint(PaintEventArgs paintEvnt)
        {
            // Get the graphics object
            Graphics gfx = paintEvnt.Graphics;
            // Create a new pen that we shall use for drawing the line
            Pen myPen = new Pen(Color.Black);
            // Loop until the coordinates reach 250 (the lower right corner of the form)
            for(int i = 0; i < 250; i = i + 50)
            {
                // Draw a 50x50 pixels rectangle
                gfx.DrawRectangle(myPen, i, i, 50, 50);
            }
        }

循环,画渐变色

 

        protected override void OnPaint(PaintEventArgs paintEvnt)
        {
            // Get the graphics object
            Graphics gfx = paintEvnt.Graphics;
            int x1 = 0;
            int y1 = 0;
            // Loop trough the 255 values red can have
            for (int i = 0; i <= 255; i++)
            {
                // 指定画刷颜色
                Color brushColor = Color.FromArgb(i, 0, 0);
                // 实心画刷用来画实心矩形
                SolidBrush myBrush = new SolidBrush(brushColor);
                // 绘制
                gfx.FillRectangle(myBrush, x1, y1, 10, 10);
                // 挨着画下一个矩形
                x1 = x1 + 10;
                //当一行结束后,画下一行
                if ((x1 % 290) == 0)
                {
                    y1 = y1 + 10;
                    x1 = 0;
                }
            }
            for (int i = 0; i <= 255; i++)
            {
                Color brushColor = Color.FromArgb(0, i, 0);
                SolidBrush myBrush = new SolidBrush(brushColor);
                gfx.FillRectangle(myBrush, x1, y1, 10, 10);
                x1 = x1 + 10;
                if ((x1 % 290) == 0)
                {
                    y1 = y1 + 10;
                    x1 = 0;
                }
            }
            for (int i = 0; i <= 255; i++)
            {
                Color brushColor = Color.FromArgb(0, 0, i);
                SolidBrush myBrush = new SolidBrush(brushColor);
                gfx.FillRectangle(myBrush, x1, y1, 10, 10);
                x1 = x1 + 10;
                if ((x1 % 290) == 0)
                {
                    y1 = y1 + 10;
                    x1 = 0;
                }
            }


        }


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
用C#简单实现的36进制转换代码发布时间:2022-07-10
下一篇:
Ajax与C#应用详细实例发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap