明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

一個(gè)畫(huà)任意形狀的窗體的例子

[摘要]繼承System.Windows.Forms.Form窗體類時(shí),重載其畫(huà)窗體形狀的事件OnPaint,就可以畫(huà)出各種自定義的窗體形狀。例子代碼是畫(huà)一個(gè)圓形窗體。protected override ...
繼承System.Windows.Forms.Form窗體類時(shí),重載其畫(huà)窗體形狀的事件OnPaint,就可以畫(huà)出各種自定義的窗體形狀。例子代碼是畫(huà)一個(gè)圓形窗體。
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);//這句是很重要的,設(shè)定窗體顯示的區(qū)域?yàn)槟闼?huà)的區(qū)域。
}