仿Win7屏保泡泡移动
生活随笔
收集整理的這篇文章主要介紹了
仿Win7屏保泡泡移动
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一個泡泡的隨機運動
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;namespace 窗體移動 {public partial class Form1 : Form{public Form1(){InitializeComponent();//加載一個窗體事件this.Load+=new EventHandler(Form1_Load);//timer的Tick事件t.Tick += new EventHandler(t_Tick);}//實例化一個Timer對象Timer t=new Timer();//定義兩個變量int b1=0,b2=0;//timer的Tick事件void t_Tick(object sender, EventArgs e){//throw new NotImplementedException();this.Left += b2;this.Top += b1;//當窗體碰撞到窗體上邊界或下邊界控制上下的變量*-1if (this.Top <= 0 || this.Bottom >= Screen.PrimaryScreen.WorkingArea.Height){b1 *= -1;}//當窗體碰撞到窗體左邊界或右邊界控制上下的變量*-1if (this.Left <= 0 || this.Right >= Screen.PrimaryScreen.WorkingArea.Width){b2 *= -1;}}//窗體加載事件private void Form1_Load(object sender, EventArgs e){//改變窗體透明度this.Opacity = 0.7;//將窗體解成一個橢圓GraphicsPath g = new GraphicsPath();g.AddEllipse(0,0,this.Width,this.Height);this.Region = new Region(g);//窗體的初始位置為(0,0)this.Location = new Point(0, 0);//生成兩個隨機數Random a = new Random();b1 = a.Next(2, 8);b2 = a.Next(2, 8);//啟動timer并設置頻率為10mst.Interval = 10;t.Start();}} }多個泡泡的隨機運動
同一個泡泡運動原理相同,可多實例化幾個窗口,這里作者提供一個方法
void showform(Form s,int b3,int b4){s.Location = new Point(s.Location.X + b3, s.Location.Y + b4);if (s.Location.Y <= 0 || s.Location.Y >= Screen.PrimaryScreen.WorkingArea.Height-s.Height){b4 *= -1;}else if (s.Location.X <= 0 || s.Location.X >= Screen.PrimaryScreen.WorkingArea.Width-s.Width){b3 *= -1;}}總結
以上是生活随笔為你收集整理的仿Win7屏保泡泡移动的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: The Byzantine Genera
- 下一篇: rt带宽限制浅析