C#实现简单气泡屏保(二)
生活随笔
收集整理的這篇文章主要介紹了
C#实现简单气泡屏保(二)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
上期續集–強化版
具體代碼如下:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Drawing.Drawing2D;//要應用GraphicsPath這個類,命名空間中必須有Drawing.Drawing2D,因為原命名空間中沒有,所以需要自行添加此命名空間.namespace Test_PaoPao {public partial class Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){this.FormBorderStyle = FormBorderStyle.None;//去邊框this.Size = new Size(200,200);this.Location = new Point(0,0);this.Opacity = 0.7;//透明度0.3Random s = new Random();//隨機生成器//氣泡背景顏色隨機this.BackColor = Color.FromArgb(s.Next(0, 255), s.Next(0, 255), s.Next(0, 255));label1.Text = "深夜食堂";label1.Font = new Font("黑體",20f);//設置字體//實例化GraphicsPath類,拿到Bx對象GraphicsPath Bx = new GraphicsPath();//使用AddEllipse方法使窗體變為圓形Bx.AddEllipse(0,0,this.Width,this.Height);//設置與控件關聯的窗體區域this.Region = new Region(Bx);timer1.Interval = 10;timer1.Start();}//設置變量使小球運動int x = 5;//水平int y = 5;//垂直private void timer1_Tick(object sender, EventArgs e){//分析:碰到頂部和底部x不變,y取反;碰到左右兩邊y不變,x取反//分兩種情況:1、先碰到底部(left不變化,top正負不斷變化) 2、先碰到右邊(left正負不斷變化,top不變)this.Left += x;this.Top += y;if (this.Top+this.Height>=Screen.PrimaryScreen.WorkingArea.Height||this.Top<=0){y = -y;//Form1 form1 = new Form1();//實例化Form1//form1.Show();//應用Form1全部屬性//form1.Location = new Point(300,100);//form1.label1.Text = "久睡成癮";}if (this.Left+this.Width>=Screen.PrimaryScreen.WorkingArea.Width||this.Left<=0){x = -x;//Form1 form2 = new Form1();//form2.Show();//form2.Location = new Point(900,200);//form2.label1.Text = "瘋狂GANK";}}} }看完的朋友記得點贊嗷,下期更精彩!!!
總結
以上是生活随笔為你收集整理的C#实现简单气泡屏保(二)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 第4代移动通信技术
- 下一篇: java泡泡屏保,js 模拟气泡屏保效果