C#轻松实现窗口气泡弹动

设置控件属性


            this.FormBorderStyle = FormBorderStyle.None;//设置窗体无边框
            this.Size = new Size(200,200);//设置窗体大小
            this.BackColor = Color.Red;//设置背景颜色
            this.Location = new Point(0,0);//设置初始内容
            this.Opacity = 0.4;//设置不透明度

            //画圆三部曲
            GraphicsPath path = new GraphicsPath();//2.实例化一个对象  为 path
            path.AddEllipse(0,0,this.Width,this.Height); //3.因为path是一个对象,有它自己的属性和方法
            this.Region = new Region(path);//1.设置与控件关联的窗口区域

            timer1.Interval = 20;//设置timer频率为20毫秒
            timer1.Start();//开启计时器

正文(实现气泡弹动)

        int x = 10;
        int y = 10;
        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Left += x;
            this.Top += y;// this.Top=this.Top+y      
            if (this.Top+this.Height>=Screen.PrimaryScreen.WorkingArea.Height || this.Top<=0)
            //移动的距离+控件的高度碰到窗口顶部或者底部
            {
                y *= -1;  //  y=y*-1

            }
            if (this.Left + this.Width >= Screen.PrimaryScreen.WorkingArea.Width || this.Left <= 0)
            //移动的距离+控件的宽度碰到窗口左端或者右端
            {
                x *= -1;  //x=x*-1
            }

        }
发布了15 篇原创文章 · 获赞 3 · 访问量 1366

猜你喜欢

转载自blog.csdn.net/weixin_44024993/article/details/105457637