打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
VA19.1 GDI plus绘图基础

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.IO;

using System.Data;

using System.Drawing;

using System.Drawing.Drawing2D ;

namespace V19.__GDI_plus绘图基础

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        //Graphics

        //创建Graphics对象的三种方式

        // Paint 事件的 PaintEvenlArgs中的 Graphics对象

        // 从Image创建 Graphics 对象

        //用CreateGraphics 方法创建Graphics 对象

        // Pen 钢笔

        //Pen 类位于System.Drawing 

        //使用GDI 中的pan 类创建钢笔,在创建钢笔时 可以为其定义线条宽度 width 和 颜色 color 属性

        // Pen p=new Pen(Color.White,1)

        //Brush 笔刷

        //SolidBrush 填充

        //TextureBrush 使用基于光栏的图像

        //LinearGradientBrush 使用颜色渐变填充图形

        //pathGeadientBrsh 使用颜色渐变填充图形

        //HatchBrush 使用各类图案填充图形

        private void Form1_Paint(object sender, PaintEventArgs e)

        {

            //Graphics g1 = e.Graphics;

            ////创建一个 Image对象

            //Bitmap imgTmp = new Bitmap(200,200);

            //Graphics g2 = Graphics.FromImage(imgTmp);

            //Graphics g3 = this.CreateGraphics();

            //MessageBox.Show("Graphics 对象");

            //  Pen  钢笔  用于储存线条属性 宽度 颜色等  

            //Graphics g = e.Graphics;

            //Pen p = new Pen(Color.Blue  ,2);

            //  // 0 80 矩形的起始点  28 长  120高              

            //g.DrawEllipse(p, 0, 80, 280, 120);

            //g.Dispose();

            // 填充

            //Graphics g = e.Graphics;

            //Brush bh = new SolidBrush(Color.Black  );

            //g.FillEllipse(bh ,0,80,280,120);

            //g.Dispose();

            //Brush 笔刷 填充图形

            //string path = @"D:\VS Projects\控制台应用程序\V19.0 GDI plus绘图基础\img\center.jpg";

            //Graphics g = e.Graphics;

            //Bitmap img;

            //if (File.Exists(path))

            //{

            //    img = new Bitmap(path);

            //    Brush br = new TextureBrush(img);

            //    g.FillEllipse(br, 0, 80, 280, 120);

            //}

            //g.Dispose();

            //3 LinearGradientBrush  线性渐变填充

            //Graphics g = e.Graphics;

            ////

            //LinearGradientBrush lgb = new LinearGradientBrush(new Point (0,80),new Point (280,120),Color.Black ,Color .Red );

            //g.FillEllipse(lgb ,0,80,280,120);

            //lgb.Dispose();

            //g.Dispose();

            //4 PathGradientBrush  圆形渐变

            //GraphicsPath gp = new GraphicsPath();

            //gp.AddEllipse(0,80,280,120);  // 添加椭圆

            //PathGradientBrush pgb = new PathGradientBrush(gp);     //圆形渐变

            //pgb.CenterColor = Color.FromArgb(255,255,0,0);      //中心颜色

            //Color[] colors ={ Color.FromArgb(255, 0, 255, 0) };

            //pgb.SurroundColors =colors ;    //环绕颜色

            //e.Graphics.FillEllipse (pgb ,0,80,280,120);

            //pgb.Dispose();

            //gp.Dispose();

            //5 HatchBrush 阴影图案

            //HatchBrush hb = new HatchBrush(HatchStyle.HorizontalBrick ,Color.Red ,Color.White );

            //e.Graphics.FillEllipse(hb ,0,80,280,120);

            //hb.Dispose(); 

            //  DrawRectangle矩形

            //Graphics g1 = e.Graphics;

            //Pen p1 = new Pen(Color.Green, 3);

            //g1.DrawRectangle(p1, 100, 10, 260, 200);

            //g1.Dispose();

            //p1.Dispose();

            //三角形 DrawPolygon多边

            //Graphics g = e.Graphics;

            //Pen p = new Pen(Color.Green, 3);

            //Point[] pg ={new Point ( 0,76),

            //        new Point (80,76),

            //    new Point (106,0) };

            //g.DrawPolygon(p,pg );

            //g.Dispose();

            //p.Dispose();

            //五角形 DrawPolygon多边   10个点

            //Graphics g = e.Graphics;

            //Pen p = new Pen(Color.Green, 3);

            //Point[] pg ={

            //        new Point ( 0,76),

            //        new Point (80,76),

            //        new Point (106,0) ,

            //        new Point ( 130,76),

            //        new Point (210,75),

            //        new Point (146,124) ,

            //        new Point (170,200),

            //        new Point (106,152),

            //        new Point (40,200),

            //        new Point ( 66,124)

            //};

            //g.DrawPolygon(p, pg);

            //g.Dispose();

            //p.Dispose();

            //绘制基本图形之椭圆、弧和 扇形

            //Graphics g = e.Graphics;

            //Pen p = new Pen(Color.Cyan, 3);

            //g.DrawEllipse(p, 0, 50, 300, 120);        //椭圆    线

            //g.DrawArc(p, 0, 50, 200, 200, 0, 120);       //弧

            ////startangle 从X轴开始沿顺时针 方向旋转的角度

            ////sweepangle 从起始角开始到弧线的结束点沿 顺时针方向角度的角 (以度为单位)

            //g.DrawPie(p, 0, 200, 300, 200, 50, 90); //扇形

            //g.Dispose();

            //p.Dispose();

            //3D 效果 

            int width = 200;

            int height = 200;

            int x = 50;

            int y = 20;

            Graphics g = e.Graphics;

            Rectangle r = new Rectangle(x,y,width,height );  //一组数组 标示矩形

            Pen p = new Pen(Color.Gray);                      // 线条

            //for (int i = y; i < 3 * y; i++)

            //{  //不断创建 画椭圆 重叠 造成阴影

            //    Rectangle tempR = new Rectangle(x, i, width, height);   //一组数组 标示矩形

            //    g.DrawEllipse(p,tempR );                               //画椭圆

            //}

            //背景椭圆

            Brush b = new SolidBrush(Color.Gainsboro  );  

            g.FillPie(b, r, 0, 360);

            //扇形 1

              b = new SolidBrush(Color.Blue );

            g.FillPie(b, r, 0, 60);

            ////扇形 2

            b = new SolidBrush(Color.Yellow);

            g.FillPie(b, r, 210, 150);

            ////扇形 3

            //b = new SolidBrush(Color.Red );

            //g.FillPie(b, r, 0, 60);

            b.Dispose();

            g.Dispose();

        }

        private void Form1_Load(object sender, EventArgs e)

        {

        }

        //更改背景颜色

        private void button2_Click(object sender, EventArgs e)

        {

            if (colorDialog1.ShowDialog() == DialogResult.OK)

            {

                this.BackColor = colorDialog1.Color;  

            }

     }

        private void button1_Click(object sender, EventArgs e)

        {

            if (fontDialog1.ShowDialog() == DialogResult.OK) {

                textBox1.Font = fontDialog1.Font;

            }

        }

    }

}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C# GDI 图形程序设计
GDI+中使用画刷
c# GDI 简单绘图(二)
GDI 图形图像
C# Graphics 绘图(及Color、Pen、Brush)
C#WinForm实践开发教程》4.图型图像GDI编程.ppt
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服