绘制矩形

Posted on 2019-01-11 20:21  努力成长静待花开  阅读(222)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:

  Graphics类的DrawRectangle方法

  public void DrawRectangle (Pen pen,Rectangel rect)  //绘制由Rectangle结构指定的矩形

  public void DrawRectangle (Pen pen,int x,int y,int width,int height)  //绘制由坐标对 宽度 高度指定的矩形

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            Pen blackPen = new Pen(Color.Red,5);
            Graphics graphics = this.CreateGraphics();
            graphics.DrawRectangle(blackPen,40,30,200,150);
        }