小例子(三)、winform控件的移动

来源:互联网 发布:vb趣味程序集锦 编辑:程序博客网 时间:2024/06/04 23:35
程序:Do You Love Me ?

说明:就是鼠标移动到“不爱”按钮上按钮就会移动到其他地方

代码:

28       //鼠标进入控件表面的事件MouseEnter29       //this.ClientSize.Width 窗体宽度30       //button2.Width 按钮的宽度31       //设置按钮的位置: button2.Location=new Point(x,y);x,y坐标32         private void button2_MouseEnter(object sender, EventArgs e)33         {34             int x = this.ClientSize.Width - button2.Width;35             int y = this.ClientSize.Height - button2.Height;36             Random r = new Random();37             button2.Location=new Point(r.Next(0,x+1),r.Next(0,y+1));38         }

 

0 0
原创粉丝点击