C#利用GDI+绘制由中心向四周渐变的图形

        private void Draw(IntPtr winHandle,Point location,Size size)
        {
            Graphics g = Graphics.FromHwnd(winHandle);
            GraphicsPath gp = new GraphicsPath();
            Rectangle rec = new Rectangle(location, size);
            gp.AddRectangle(rec);
            Color[] surroundColor = new Color[] { Color.White };
            PathGradientBrush pb = new PathGradientBrush(gp);
            pb.CenterColor = Color.Green;
            pb.SurroundColors = surroundColor;
            g.FillPath(pb, gp);   
        }

        // 测试

        private void btnTest_Click(object sender, EventArgs e)
        {
            Draw(pictureBox1.Handle, new Point(10, 10),new Size( 20, 20));
        }

posted @ 2011-10-23 19:49  lanmiao  阅读(1389)  评论(0编辑  收藏  举报