GDI编程开发

1、GDI:图形设备接口,是windows提供的图形技术,可以方便的在屏幕、打印机及其它输出设备上输出各种颜色各种形状的图形;   

(1)命名空间:using System.Drawing.Text;                

                  using System.Drawing.Imaging;                

                  using System.Drawing.Drawing2D;

2、GDI+是对以前的版本的一个升级,添加了许多新的功能;是托管的只有在.net的运行库下才能运行.   

(1)画图的时候一般情况下,写在paint事件中   

(2)Pen p = new Pen(Color.Red,20);        

       Brush brush = new SolidBrush(Color.Yellow);//刷子派生出了很多刷子,这个是固体的        

       Color c = Color.Black;//定义颜色        

       Color c1 = Color.FromArgb(200, 200, 200);//定义颜色,四个参数可以设置透明度        

       Font mf = new Font("Arial",12);//封闭类,无法继承        

       Point p1 = new Point(0,0);        

       Point p2 = new Point(100,100);//定义点可以画线        

       f.DrawLine(p, p1, p2);        

       Graphics f = this.button2.CreateGraphics();//在控件中画图   

(3)用按钮画图不会重绘,用Timer事件反复去画;在paint事件中可重绘;   

(4)DrawString添加字符串

例子:八卦图形

Pen p = new Pen(Color.Black, 3);          

Pen p12 = new Pen(Color.Yellow, 6);           

Pen p13 = new Pen(Color.Black, 3);           

Brush brush = new SolidBrush(Color.Red);            

 Brush brush1 = new SolidBrush(Color.Blue);            

Font mf = new Font("宋体", 12);            

Graphics f = e.Graphics;             //工具            

//三个圆            

f.DrawEllipse(p, 150, 150, 250,250);       

f.DrawEllipse(p12, 154, 154, 243, 243);            

f.DrawEllipse(p13, 157, 157, 236, 236);            

//四个半圆            

f.FillPie(brush, 157, 157, 236, 236, 90, 180);            

f.FillPie(brush1, 157, 157, 236, 236, 270, 180);            

f.FillPie(brush1, 220, 157, 118, 118, 90, 180);            

f.FillPie(brush, 216, 275, 118, 118, 270, 180);             //两个小圆            

f.FillEllipse(brush,256,200,38,38);            

f.FillEllipse(brush1,256, 308, 38, 38);

原文地址:https://www.cnblogs.com/heluo/p/2390804.html