Winform中不规则窗体制作的解决方案(再续)

下面我给大家介绍一个更好的例子,该实例的界面就和微软的Windows Media Player 7的界面差不多。不过在这个例子中,我只是介绍了如何制作出界面,并没有实现媒体播放的功能,要实现那些功能,还需要您自行完善。

1.将某种颜色设置为窗体的背景颜色,然后将窗体的TransparenceKey属性设置为那种颜色,同时将窗体的FormBorderStyle属性设置为None。
2.重载Form_Paint()函数:

protected   override   void   OnPaint(PaintEventArgs e)
// 也可以参考下面这种方式
this .Paint  +=   new  System.Windows.Form.PaintEventHandler(Form_Paint)。

 3.程序的主体部分的函数如下:

private   void  Form_Paint( object  sender, PaintEventArgs e)
{
    Graphics g 
= e.Graphics;
        Rectangle mainRect 
= new Rectangle(00695278);
        Region mainRegion 
= new Region(mainRect);
        e.Graphics.SetClip(mainRegion, CombineMode.Replace);
            Point point1 
= new Point(032);
        Point point2 
= new Point(920);
        Point point3 
= new Point(2113);
        Point point4 
= new Point(349);
            
// 创建一个以点为元素的数组
        Point[] curvePoints = { point1, point2, point3, point4 };
        
// 创建一个GraphicsPath对象并添加一条曲线
        GraphicsPath myPath = new GraphicsPath();
        myPath.AddCurve(curvePoints, 
030.8f);
        myPath.AddLine(
3693789);
        point1.X
=378;point1.Y=9;
        point2.X
=387;point2.Y=5;
        point3.X
=394;point3.Y=0;
        Point[] curvePoints2 
= { point1, point2, point3 };
        myPath.AddCurve(curvePoints2, 
020.8f);
        myPath.AddLine(
394000);
        Region ExcludeRegion3 
= new Region(myPath);
        e.Graphics.ExcludeClip(ExcludeRegion3);

        GraphicsPath myPath3 
= new GraphicsPath();
        point1.X
=0;point1.Y=180;
        point2.X
=19;point2.Y=198;
        point3.X
=62;point3.Y=204;
        point4.X
=83;point4.Y=221;
        Point point5 
= new Point(93248);
        Point point6 
= new Point(102267);
        Point point7 
= new Point(125278);
        Point[] curvePoints3 
= { point1, point2, point3, point4, point5, point6, point7 };
        myPath3.AddCurve(curvePoints3, 
060.8f);
        myPath3.AddLine(
12527890300);
        myPath3.AddLine(
903000300);
        Region ExcludeRegion2 
= new Region(myPath3);
        e.Graphics.ExcludeClip(ExcludeRegion2);
        point1.X
=454;point1.Y=0;
        point2.X
=470;point2.Y=12;
        point3.X
=481;point3.Y=34;
        Point[] curvePoints4 
= { point1, point2, point3 };
        GraphicsPath myPath2 
= new GraphicsPath();
        myPath2.AddCurve(curvePoints4, 
020.8f);
        myPath2.AddLine(
4813048176);
        myPath2.AddLine(
4817649576);
        myPath2.AddLine(
495764950);
        Region ExcludeRegion4 
= new Region(myPath2);
        e.Graphics.ExcludeClip(ExcludeRegion4);
        GraphicsPath myPath5 
= new GraphicsPath();
        point1.X
=481;point1.Y=76;
        point2.X
=494;point2.Y=115;
        point3.X
=481;point3.Y=158;
        Point[] curvePoints5 
= { point1, point2, point3 };
        myPath5.AddCurve(curvePoints5, 
020.8f);
        myPath5.AddLine(
481158481279);
        myPath5.AddLine(
481255495279);
        myPath5.AddLine(
4952794950);
        Region ExcludeRegion6 
= new Region(myPath5);
        e.Graphics.ExcludeClip(ExcludeRegion6);

        point1.X
=480;point1.Y=250;
        point2.X
=469;point2.Y=264;
        point3.X
=446;point3.Y=278;
        Point[] curvePoints6 
= { point1, point2, point3 };
        GraphicsPath myPath4 
= new GraphicsPath();
        myPath4.AddCurve(curvePoints6, 
020.8f);
        myPath4.AddLine(
450277495279);
        Region ExcludeRegion5 
= new Region(myPath4);
        e.Graphics.ExcludeClip(ExcludeRegion5);

        e.Graphics.DrawImage(img, 
00695,278);

        
// 重设剪切好的区域
        e.Graphics.ResetClip();
}

该函数运用Region类和GraphicsPath类实现了程序的主界面,函数中具体的数据可能会因图片大小等原因而有所不同

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值