.Net学习笔记----2015-07-10(GDI绘图)

GDI+(Graphics Device Interface) 是一种绘图装置接口,可将应用程序和绘图硬件分隔,让我们能够编写与装置无关的应用程序。

它可以让我们不需要注意特定显示装置的详细数据,便可在屏幕或打印机显示信息。

我们可以呼叫GDI+类别提供的方法,然后这些方法会适当的呼叫特定的装置驱动程序,而完成绘图。而且与.NET进行了更好的融合

GDI 

        private void Form1_Load(object sender, EventArgs e)
        {
            //直线绘制?一支笔,颜色,一张纸,两点一线,绘制直线的人(对象)
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();//new Graphics();
            //创建画笔对象
            Pen pen = new Pen(Brushes.Red);
            //创建两个点
            Point p1 = new Point(30, 50);
            Point p2 = new Point(200, 200);
            //

            g.DrawLine(pen, p1, p2);
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();//new Graphics();
            //创建画笔对象
            Pen pen = new Pen(Brushes.Red);
            //创建两个点
            Point p1 = new Point(30, 50);
            Point p2 = new Point(200, 200);
            //

            g.DrawLine(pen, p1, p2);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Pen pen = new Pen(Brushes.Green);
            Size size = new System.Drawing.Size(160,80);
            Rectangle rec = new Rectangle(new Point(50,50),size);
            g.DrawRectangle(pen, rec);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Pen pen = new Pen(Brushes.Blue);
            Size size = new System.Drawing.Size(150, 150);
            Rectangle rec = new Rectangle(new Point(150,150),size);
            g.DrawPie(pen, rec, 60, 60);

        }

        private void button4_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            g.DrawString("老婆是最美的", new Font("黑体", 20, FontStyle.Bold), Brushes.Black, new Point(300, 300));
        }
    }

 

你可能感兴趣的:(.net)