画出各种自定义的窗体形状

一个画任意形状的窗体的例子

继承System.Windows.Forms.Form窗体类时,重载其画窗体形状的事件OnPaint,就可以画出各种自定义的窗体形状。例子代码是画一个圆形窗体。
protected override void OnPaint(PaintEventArgs e) 
{
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(20,20,110,110);
//gp.AddLine(30,30,110,110);

Matrix RotationTransform = new Matrix(1,0, 0,1,1,1); // rotation matrix
//Matrix TranslationTransform = new Matrix(1, 0, 0, 1, 0, 0); // translation matrix
PointF TheRotationPoint = new PointF(110.0f, 110.0f); // rotation point 
// rotate the rotation transformation matrix f degrees around TheRotationPoint
RotationTransform.RotateAt(f, TheRotationPoint); 
//Call the Transform method of the Graphics Path in order to multiply it by the rotation matrix and rotate the balloon
gp.Transform(RotationTransform);
e.Graphics.DrawPath(Pens.Black, gp);
f=f+10;
this.Region=new Region(gp);//这句是很重要的,设定窗体显示的区域为你所画的区域。
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值