气泡案例
this.Top:表示窗体上边框与屏幕顶部的距离
this.Left:表示窗体左边框与屏幕左边的距离
Screen.PrimaryScreen.WorkingArea.Width:屏幕的宽,不包括任务栏
Screen.PrimaryScreen.Bounds.Width:屏幕的宽,包括任务栏
Screen.PrimaryScreen.WorkingArea.Height:屏幕的高,不包括任务栏
Screen.PrimaryScreen.Bounds.Height:屏幕的高,包括任务栏
Timer:计时器控件,控制某种行为在特定时间的运行
Interval属性:设置计时器的频率
双击计时器会创建对应的tick事件
窗体平移
窗体平移:
窗体从屏幕左上角——》屏幕右上角——》屏幕右下角——》屏幕左下角——》屏幕左上角循环
多个计时器:
重点考虑每个计时器中的行为,开始/停止计时器的时机
代码:
private void Form1_Load(object sender, EventArgs e)
{
this.Location = new Point(0, 0);//窗口位置
this.BackColor = Color.Beige;//窗口背景颜色
this.FormBorderStyle = FormBorderStyle.None;//窗体边框样式
this.Size = new Size(200, 200);//窗体大小
timer1.Start();//开启计时器
}
int w = Screen.PrimaryScreen.WorkingArea.Width;//获取屏幕宽度(WorkingArea,不包括任务栏)
int h = Screen.PrimaryScreen.Bounds.Height;//获取屏幕宽度(Bounds,包括任务栏)
private void timer1_Tick_1(object sender, EventArgs e)
{
this.Left += 10;//即this.Left=this.Left+10,使窗体右移
//到达屏幕右上角关闭计时器1,开启计时器2
if (this.Width + this.Left >= w)
{
timer1.Stop();
timer2.Start();
}
}
private void timer2_Tick_1(object sender, EventArgs e)
{
this.Top += 10;//即this.top=this.top+10,使窗体下移
//到达屏幕右下角关闭计时器2,开启计时器3
if (this.Height + this.Top >= h)
{
timer2.Stop();