仿win7屏保泡泡移动
番茄系统家园 · 2021-07-16 07:10:08

一个泡泡的随机运动
;;;;;;;;窗体移动{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();//加载一个窗体事件this.LoadnewEventHandler(Form1_Load);//timer的Tick事件t.TicknewEventHandler(t_Tick);}//实例化一个Timer对象TimertnewTimer();//定义两个变量intb10,b2//timer的Tick事件voidt_Tick(objectsender,EventArgse){//thrownewNotImplementedException();this.Leftb2;this.Topb1;//当窗体碰撞到窗体上边界或下边界控制上下的变量*-1if(this.Top0||this.BottomScreen.PrimaryScreen.WorkingArea.Height){b1*-1;}//当窗体碰撞到窗体左边界或右边界控制上下的变量*-1if(this.Left0||this.RightScreen.PrimaryScreen.WorkingArea.Width){b2*-1;}}//窗体加载事件privatevoidForm1_Load(objectsender,EventArgse){//改变窗体透明度this.Opacity0.7;//将窗体解成一个椭圆GraphicsPathgnewGraphicsPath();g.AddEllipse(0,0,this.Width,this.Height);this.RegionnewRegion(g);//窗体的初始位置为0,0this.LocationnewPoint(0,0);//生成两个随机数RandomanewRandom();b1a.Next(2,8);b2a.Next(2,8);//启动timer并设置频率为10mst.Interval10;t.Start();}}}
多个泡泡的随机运动
同一个泡泡运动原理相同可多实例化几个窗口这里作者提供一个方法
voidshowform(Formsintb3,intb4){s.LocationnewPoint(s.Location.Xb3,s.Location.Yb4);if(s.Location.Y0||s.Location.YScreen.PrimaryScreen.WorkingArea.Height-s.Height){b4*-1;}elseif(s.Location.X0||s.Location.XScreen.PrimaryScreen.WorkingArea.Width-s.Width){b3*-1;}}
免责声明: 凡标注转载/编译字样内容并非本站原创,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如果你觉得本文好,欢迎推荐给朋友阅读;本文链接: https://m.nndssk.com/post/13618.html。
