高级绘图

Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace 控件模拟别人的
{
    
public partial class Form1 : Form
    
{
        
private RectangleF selectorRct = Rectangle.Empty;
        
private int opacity = 200;

        
public Form1()
        
{
            InitializeComponent();
        }


        
private void Form1_Paint(object sender, PaintEventArgs e)
        
{
            
//e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            
//DrawSelector(e);
        }


        
private void DrawSelector(PaintEventArgs e)
        
{
            selectorRct.X 
= this.Width/2;
            selectorRct.Y 
= this.Height/2;

            GraphicsPath gp 
= CreateRoundedRectangle(selectorRct, 100);

            Pen p
=new Pen(Color.FromArgb(200,Color .Black));
            e.Graphics .DrawPath(p,gp);
            PathGradientBrush pgb
=new PathGradientBrush(gp);

            Color[] surroundColor 
= new Color[] {
                Color.FromArgb(opacity, 
227243255),
                Color.FromArgb(opacity, 
189205233),
                Color.FromArgb(opacity, 
103150161),
                Color.FromArgb(opacity, 
76118146)}
;
            
float[] positions = new float[] { 0f, .82f, .85f, 1.0f };
             
            ColorBlend blnd 
= new ColorBlend();
            blnd.Positions 
= positions;
            blnd.Colors 
= surroundColor;
            pgb.InterpolationColors 
= blnd;
            pgb.SurroundColors 
= surroundColor;

            e.Graphics.FillPath(pgb, gp);

            p.Dispose();
            gp.Dispose();
            pgb.Dispose();            
        }


        
public static GraphicsPath CreateRoundedRectangle(RectangleF rct, int radius)
        
{
            GraphicsPath gp 
= new GraphicsPath();
            PointF pt1 
= new PointF(rct.X + radius, rct.Y);
            PointF pt2 
= new PointF(rct.X + rct.Width - radius, rct.Y);
            RectangleF rct1 
= new RectangleF(rct.X, rct.Y, radius, radius);

            gp.AddArc(rct1, 180f, 90f);
            gp.AddLine(pt1, pt2);

            rct1.Location 
= pt2;
            gp.AddArc(rct1, 270f, 90f);

            pt1 
= new PointF(rct.X + rct.Width, rct.Y + radius);
            pt2 
= new PointF(rct.X + rct.Width, rct.Y + rct.Height - radius);
            gp.AddLine(pt1, pt2);

            rct1.Location 
= new PointF(rct.X + rct.Width - radius, rct.Y + rct.Height - radius);
            gp.AddArc(rct1, 0f, 90f);

            pt1 
= new PointF(rct.X + rct.Width - radius, rct.Y + rct.Height);
            pt2 
= new PointF(rct.X + radius, rct.Y + rct.Height);
            gp.AddLine(pt1, pt2);

            rct1.Location 
= new PointF(rct.X, rct.Y + rct.Height - radius);
            gp.AddArc(rct1, 90f, 90f);

            gp.CloseFigure();

            
return gp;
        }


        
private void panel1_Paint(object sender, PaintEventArgs e)
        
{
            e.Graphics.SmoothingMode 
= SmoothingMode.AntiAlias;
            DrawSelector(e);
            
//panel1.Refresh();          
        }

    }

}

转载于:https://www.cnblogs.com/cxfcxf8/archive/2008/05/01/1179049.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值