if(this.Top+this.Height>=Screen.PrimaryScreen.Bounds.Height||this.Top<=0)//判断窗体高度加上上边缘高度与桌面高度{
y =-y;}if(this.Left+this.Width>=Screen.PrimaryScreen.Bounds.Width||this.Left<=0)//判断窗体宽度加上左边缘高度与桌面宽度{
x =-x;}
(4).整体代码的实现
privatevoid 气泡案例_Load(object sender,EventArgs e){this.Location =newPoint(0,0);//设置窗体位置this.FormBorderStyle = FormBorderStyle.None;//设置窗体无边框this.Size =newSize(200,200);//设置窗体大小this.Opacity =0.4;//设置不透明度this.BackColor = Color.Blue;//设置背景颜色//将窗体画成圆形,实例化GraphicsPath path =newGraphicsPath();
path.AddEllipse(0,0,this.Width,this.Height);this.Region =newRegion(path);
timer1.Start();//开启计时器}int x =5;int y =8;privatevoidtimer1_Tick(object sender,EventArgs e){this.Top += y;this.Left += x;if(this.Top+this.Height>=Screen.PrimaryScreen.Bounds.Height||this.Top<=0)//判断窗体高度加上上边缘高度与桌面高度{
y =-y;}if(this.Left+this.Width>=Screen.PrimaryScreen.Bounds.Width||this.Left<=0)//判断窗体宽度加上左边缘高度与桌面宽度{
x =-x;}}