public partial class Form1 : Form { public Form1() { InitializeComponent(); } private Timer t = new Timer(); private Timer t1 = new Timer(); private void Form1_Load(object sender, EventArgs e) { t.Interval = 10; t.Tick += new EventHandler(button4_Click);//到达时间的时候执行事件; t1.Interval = 10; t1.Tick += new EventHandler(button5_Click);//到达时间的时候执行事件;
} //左移 private void button4_Click(object sender, EventArgs e) { Rectangle rect = new Rectangle(); rect = Screen.GetWorkingArea(this); t1.Stop(); t.Start();
this.Left--; if (this.Left < 0) { this.Left = rect.Width; }
} //右移 private void button5_Click(object sender, EventArgs e) { Rectangle rect = new Rectangle(); rect = Screen.GetWorkingArea(this); t.Stop(); t1.Start(); this.Left++; if (this.Left >= rect.Width) { this.Left = 0; } }
下this.Top--;
左 this.Left--;
右 this.Left++;
this.Location = new Point(this.Location.X + 1, this.Location.Y); //从左到右
this.Location = new Point(this.Location.X - 1, this.Location.Y); //从右到左this.Location = new Point(this.Location.X, this.Location.Y + 1); //从上到下
this.Location = new Point(this.Location.X, this.Location.Y - 1); //从下到上this.Location = new Point(this.Location.X + 1, this.Location.Y + 1); //从左上到右下
this.Location = new Point(this.Location.X + 1, this.Location.Y + 1); //从右下到左上
// 其他方向,照此发挥this.Location.X+this.Width == 屏幕宽度 这时 this.Location.X =0 //其他类似处理
{
public Form1()
{
InitializeComponent();
} private Timer t = new Timer();
private Timer t1 = new Timer(); private void Form1_Load(object sender, EventArgs e)
{
t.Interval = 10;
t.Tick += new EventHandler(button4_Click);//到达时间的时候执行事件;
t1.Interval = 10;
t1.Tick += new EventHandler(button5_Click);//到达时间的时候执行事件;
} //左移
private void button4_Click(object sender, EventArgs e)
{
Rectangle rect = new Rectangle();
rect = Screen.GetWorkingArea(this);
t1.Stop();
t.Start();
this.Left--;
if (this.Left < 0)
{
this.Left = rect.Width;
}
}
//右移
private void button5_Click(object sender, EventArgs e)
{
Rectangle rect = new Rectangle();
rect = Screen.GetWorkingArea(this);
t.Stop();
t1.Start(); this.Left++;
if (this.Left >= rect.Width)
{
this.Left = 0;
}
}
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height
屏幕
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height
工作区
C# codeScreen.PrimaryScreen.WorkingArea.Height;
Screen.PrimaryScreen.WorkingArea.Width;
this.Location.X=0;
改成
this.Location = new Point(0, this.Location.Y); //从左到右
this.Location = new Point(this.Location.X + 5, this.Location.Y);
if (this.Location.X + this.Width == Screen.PrimaryScreen.Bounds.Width)
this.Location = new Point(0, this.Location.Y); 大哥 这样还是不行啊 移出窗体后还是无法从屏幕的左边出来
if (this.Location.X > Screen.PrimaryScreen.Bounds.Width)
this.Location = new Point(0, this.Location.Y);