仿Win7屏保泡泡移动
生活随笔
收集整理的這篇文章主要介紹了
仿Win7屏保泡泡移动
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一個(gè)泡泡的隨機(jī)運(yùn)動
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();//加載一個(gè)窗體事件this.Load+=new EventHandler(Form1_Load);//timer的Tick事件t.Tick += new EventHandler(t_Tick);}//實(shí)例化一個(gè)Timer對象Timer t=new Timer();//定義兩個(gè)變量int b1=0,b2=0;//timer的Tick事件void t_Tick(object sender, EventArgs e){//throw new NotImplementedException();this.Left += b2;this.Top += b1;//當(dāng)窗體碰撞到窗體上邊界或下邊界控制上下的變量*-1if (this.Top <= 0 || this.Bottom >= Screen.PrimaryScreen.WorkingArea.Height){b1 *= -1;}//當(dāng)窗體碰撞到窗體左邊界或右邊界控制上下的變量*-1if (this.Left <= 0 || this.Right >= Screen.PrimaryScreen.WorkingArea.Width){b2 *= -1;}}//窗體加載事件private void Form1_Load(object sender, EventArgs e){//改變窗體透明度this.Opacity = 0.7;//將窗體解成一個(gè)橢圓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);//生成兩個(gè)隨機(jī)數(shù)Random a = new Random();b1 = a.Next(2, 8);b2 = a.Next(2, 8);//啟動timer并設(shè)置頻率為10mst.Interval = 10;t.Start();}} }多個(gè)泡泡的隨機(jī)運(yùn)動
同一個(gè)泡泡運(yùn)動原理相同,可多實(shí)例化幾個(gè)窗口,這里作者提供一個(gè)方法
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;}}總結(jié)
以上是生活随笔為你收集整理的仿Win7屏保泡泡移动的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: The Byzantine Genera
- 下一篇: linux命名空间(namespace)