现在的位置: 首页 > 综合 > 正文

一个用gdi+写的代码

2013年01月11日 ⁄ 综合 ⁄ 共 1518字 ⁄ 字号 评论关闭
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;     
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace WindowsApplication2

{

    public partial class Form1 : Form
    {

        protected override void OnPaint(PaintEventArgs e)
        {
            Brush linerbrush = new LinearGradientBrush(new Rectangle(10, 10, 59, 59), Color.Red , Color.White, 45);
            Graphics g = e.Graphics;
            g.FillRectangle(linerbrush, new Rectangle(10, 10, 590, 590));////作出来的效果那是一个棒!!
            linerbrush.Dispose();////这句那是相当的重要,我就忘了,机子就变得很慢了!
            Rectangle r1 = new Rectangle(10, 10, 59, 59);
            Region r = new Region(r1);////可以用这句把path或rectrangle等化为region,也可以用union加上一些东西。OK
            GraphicsPath path;
            path = new GraphicsPath(new Point[] { new Point(10, 10), new Point(150, 10), new Point(200, 150), new Point(10, 150), new Point(200, 160) },
                new byte[] { (byte)PathPointType.Start, (byte)PathPointType.Line, (byte)PathPointType.Line, (byte)PathPointType.Line, (byte)PathPointType.Line });
            //e.Graphics.DrawPath(Pens.Black, path);
            r.Union(path);
            //e.Graphics.FillRegion(Brushes.Black, r);////这句证明fillregion是用来画黑图的。
            //e.Graphics.DrawPath(Pens.Black, path);////这句证明了drawpath是用来画路径的 draw的都是path,而fill的都是region。

        }////为了能够重载,所以放在了这里。
  
  /// <summary>
  /// 只要是可以认真分析出来的图形,都可以画出来。
  /// </summary>
    
 
        public Form1()
        {
            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }

}

抱歉!评论已关闭.