C# winfrm中做的来回漂动窗口问题!

莫克168 2009-04-20 11:01:55
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace floatingForm
{
public partial class FloatingForm : Form
{
public FloatingForm()
{
InitializeComponent();
}

private void timer1_Tick(object sender, EventArgs e)
{
Point p = new Point(0,370);
//p.X = this .DesktopLocation .X ;
while (this .DesktopLocation .X <=0)
{
for (int i = 0; i < this.DesktopBounds.Width; i++)
{
Point p1 = new Point(this.DesktopLocation.X + 1, this.DesktopLocation.Y);
this.DesktopLocation = p1;
//p = p1;
}


if (this.DesktopLocation.X == this.DesktopBounds.Width)
{
for (int i = this.DesktopBounds.Width; i > 0; i++)
{
//Point p2 = new Point(20, 370);
//this.DesktopLocation = p2;

Point p2 = new Point(this.DesktopLocation.X - 1, this.DesktopLocation.Y);

this.DesktopLocation = p2;
}

}

this.DesktopLocation = p;

}



}

private void FloatingForm_Load(object sender, EventArgs e)
{
Point p = new Point(0, 370);
this.DesktopLocation = p;
}


}
}


在程序运行时,只能够来回一次,我想做的是能够不断自动来回的,想了好半天还是没头绪,小弟我是初学者,希望有哪位大大能够帮忙解答一下,非常感谢!!!
...全文
74 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
LoveLife_Go 2009-04-21
  • 打赏
  • 举报
回复
学习
zhujinbo 2009-04-21
  • 打赏
  • 举报
回复
设置一下x,y坐标,分别判断xy的边界值,然后写个for语句实现x++,Y++,X--,y--就行了
wonsoft 2009-04-21
  • 打赏
  • 举报
回复
首先设置一个初始值,然后不停修改变量,到一定条件时又还原到初始值,这样不停地循环,就可以了。
xufzu123 2009-04-21
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FloatForm
{
public partial class Form1 : Form
{
int x;
int y;
int incre_x;
int incre_y;
public Form1()
{
InitializeComponent();
x = 0;
y = 370;
incre_x = 10;
incre_y = 10;
this.Location = new Point(x, y);
timer1.Start();
}

private void timer1_Tick(object sender, EventArgs e)
{
x += incre_x;
y += incre_y;
if (x > 1024 || x < 0)
incre_x *= -1;
if (y > 768 || y < 0)
incre_y *= -1;
this.Location = new Point(x, y);
}
}
}

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧