Winfrom里可以设置窗口或控件的剪裁区域,可以设置任意形状,比如我以前一个控件,它是一个状态栏,右侧被我剪裁成类似梯形: protected override void OnResize(EventArgs e) { base.OnResize(e); GraphicsPath path = new GraphicsPath(); path.StartFigure(); Point LT = new Point(0, 0);//左上角 Point RT = new Point(Width, 0);//右上角 Point LB = new Point(0, Height);//左下角 Point RB = new Point(Width, Height);//右下角 Point Polygon2 = new Point(Width - 4, 0); Point Polygon4 = new Point(Width, 4); path.AddLine(LT, LB); path.AddLine(LB, RB); path.AddLine(RB, Polygon4); path.AddLine(Polygon4, Polygon2); path.AddLine(Polygon2, LT); path.CloseFigure(); this.Region = new System.Drawing.Region(path); } 设置了Region后,控件只有位于剪裁区域内的部分才会被显示。其实,我觉得控件可以通过其它方法来模拟圆形,比如让控件背景色和其容器背景色一样,然后你画圆形图案,这样看起来不就是圆形效果了吗?
VBPK内置在VS2008SP1/VS2010里面,VS2005要自己下载安装。
{
base.OnResize(e);
GraphicsPath path = new GraphicsPath(); path.StartFigure(); Point LT = new Point(0, 0);//左上角
Point RT = new Point(Width, 0);//右上角
Point LB = new Point(0, Height);//左下角
Point RB = new Point(Width, Height);//右下角 Point Polygon2 = new Point(Width - 4, 0);
Point Polygon4 = new Point(Width, 4); path.AddLine(LT, LB);
path.AddLine(LB, RB);
path.AddLine(RB, Polygon4);
path.AddLine(Polygon4, Polygon2);
path.AddLine(Polygon2, LT); path.CloseFigure(); this.Region = new System.Drawing.Region(path);
}
设置了Region后,控件只有位于剪裁区域内的部分才会被显示。其实,我觉得控件可以通过其它方法来模拟圆形,比如让控件背景色和其容器背景色一样,然后你画圆形图案,这样看起来不就是圆形效果了吗?