大体意思是这样,我有一个Form1和Form2,form1的尺寸(237,237),form2做成了异型窗体--小球,在form1运行小球,为什么每当小球在from1范围的时候,小球速度就会变慢.在form1范围之外就很正常,究竟是怎么回事,各位高手帮帮兄弟忙吧!谢谢.
解决方案 »
- 关于Ajax控件的位置固定
- 画checkbox的时候怎么把选框放在矩形的边上
- C#打包,将sql数据库也打进去 ,怎么弄, 那位高手给解决下?
- 使用DirectoryEntry控制IIS的问题
- cs结构的软件如何保存一些用户信息?
- 客户端控件的值如何传递给服务器端控件呢
- 如何设置comboBox选择哪一项
- 装好VS .NET 2005以后,原来2003关联的帮助也变成MSDN2005了,怎么调过来?
- 求救!!!关于弹出窗体和关闭弹出窗体
- 请问将DataTable的数据批量导入数据库中,用什么办法效率最高
- 请问一下,TCP做即时通信软件的关闭
- xml架构()Schema生成强类型DataSet的问题???求高人指点!!!
运行小球代码在Form2里面,但是数据是用form1显示出来。
private void timer1_Tick(object sender, EventArgs e)
{
string str1;
System.Windows.Forms.Screen screen = Screen.PrimaryScreen; //sceen
System.Drawing.Rectangle rct = screen.Bounds; //screen
sw = int.Parse(rct.Width.ToString()); //screen width
sh = int.Parse(rct.Height.ToString()); //screen height
C1.path = Application.StartupPath + "\\Soccer.ini";
System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"Fidget Button Sound.wav"); int x, y, w, h;
x = this.Left;
y = this.Top;
w = sw - 117;
h = sh - 113;
if (mode == 1)
{
str1 = C1.IniReadValue("Practice", "speed1");
s = int.Parse(str1);
y = y - (dy * s); //y坐标
x = x - (dx * s);
if ((x < 0 ||
x > w) && //(0,0>y>max) (max,0>y>max)
(0 < y &&
y < h))
{
player.Play();
dx = -dx;
} if ((x < 0 || //(0,0) (max,0)(0,max)(max,max)
x > w) &&
(y < 0 ||
y > h))
{
player.Play();
dx = -dx;
dy = -dy;
} if ((0 < x && //(0>x>max,0) (0>x>max,max)
x < w) &&
y < 0 ||
y > h)
{
player.Play();
dy = -dy;
} if ((0 < x ||
x < w) &&
y > h)
{
Score = Score + 1;
if (Score == 20)
{
str1 = C1.IniReadValue("Practice", "speed2");
s = int.Parse(str1);
} if (Score == 40)
{
str1 = C1.IniReadValue("Practice", "speed3");
s = int.Parse(str1);
}
if (Score > 999)
{
Level = 3;
Score = 0;
}
} this.Left = x;
this.Top = y;
}
if (mode == 2)
{
str1 = C1.IniReadValue("insane", "speed");
s = int.Parse(str1);
y = y - (dy * s);
if (y < 0 ||
y > h)
{
dy = -dy;
}
this.Top = y;
}
} 下面是在Form1 显示出数据的代码: private void timer2_Tick(object sender, EventArgs e)
{
//小球的次数
int j;
/*if (f1.Score >0)
{
this.Show();
this.Activate();
f1.Activate();
}*/
// f1.Show();
j = f1.Score % 10;
pictureBox15.Image = Image.FromFile(@"Picture\Letters\timer-" + j.ToString() + ".bmp");
j = f1.Score % 100 / 10;
pictureBox14.Image = Image.FromFile(@"Picture\Letters\timer-" + j.ToString() + ".bmp");
j = f1.Score / 100;
pictureBox13.Image = Image.FromFile(@"Picture\Letters\timer-" + j.ToString() + ".bmp");
//Level
pictureBox12.Image = Image.FromFile(@"Picture\Letters\timer-1.bmp");
if (f1.Score == 20)
pictureBox12.Image = Image.FromFile(@"Picture\Letters\timer-2.bmp");
if (f1.Score == 40 ||
f1.Level == 3)
pictureBox12.Image = Image.FromFile(@"Picture\Letters\timer-3.bmp"); //Higthest
string str = C1.IniReadValue("Highest", "Soccer");
h = int.Parse(str);
if (f1.Score > h)
h = f1.Score; h1 = h % 10;
pictureBox18.Image = Image.FromFile(@"Picture\Letters\timer-" + h1.ToString() + ".bmp");
h2 = h % 100 / 10;
pictureBox17.Image = Image.FromFile(@"Picture\Letters\timer-" + h2.ToString() + ".bmp");
h3 = h / 100;
pictureBox16.Image = Image.FromFile(@"Picture\Letters\timer-" + h3.ToString() + ".bmp");
C1.highsoccer = h3 * 100 + h2 * 10 + h1;
C1.IniWriteValue("Highest", "Soccer", C1.highsoccer.ToString());
}
private void timer1_Tick(object sender, EventArgs e)
{
string str1;
System.Windows.Forms.Screen screen = Screen.PrimaryScreen; //sceen
System.Drawing.Rectangle rct = screen.Bounds; //screen
sw = int.Parse(rct.Width.ToString()); //screen width
sh = int.Parse(rct.Height.ToString()); //screen height
C1.path = Application.StartupPath + "\\Soccer.ini";
System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"Fidget Button Sound.wav"); int x, y, w, h;
x = this.Left;
y = this.Top;
w = sw - 117;
h = sh - 113;
if (mode == 1)
{
str1 = C1.IniReadValue("Practice", "speed1");
s = int.Parse(str1);
y = y - (dy * s); //y坐标
x = x - (dx * s);
if ((x < 0 ||
x > w) && //(0,0>y>max) (max,0>y>max)
(0 < y &&
y < h))
{
player.Play();
dx = -dx;
} if ((x < 0 || //(0,0) (max,0)(0,max)(max,max)
x > w) &&
(y < 0 ||
y > h))
{
player.Play();
dx = -dx;
dy = -dy;
} if ((0 < x && //(0>x>max,0) (0>x>max,max)
x < w) &&
y < 0 ||
y > h)
{
player.Play();
dy = -dy;
} if ((0 < x ||
x < w) &&
y > h)
{
Score = Score + 1;
if (Score == 20)
{
str1 = C1.IniReadValue("Practice", "speed2");
s = int.Parse(str1);
} if (Score == 40)
{
str1 = C1.IniReadValue("Practice", "speed3");
s = int.Parse(str1);
}
if (Score > 999)
{
Level = 3;
Score = 0;
}
} this.Left = x;
this.Top = y;
}
if (mode == 2)
{
str1 = C1.IniReadValue("insane", "speed");
s = int.Parse(str1);
y = y - (dy * s);
if (y < 0 ||
y > h)
{
dy = -dy;
}
this.Top = y;
}
} 下面是在Form1 显示出数据的代码: private void timer2_Tick(object sender, EventArgs e)
{
//小球的次数
int j;
/*if (f1.Score >0)
{
this.Show();
this.Activate();
f1.Activate();
}*/
// f1.Show();
j = f1.Score % 10;
pictureBox15.Image = Image.FromFile(@"Picture\Letters\timer-" + j.ToString() + ".bmp");
j = f1.Score % 100 / 10;
pictureBox14.Image = Image.FromFile(@"Picture\Letters\timer-" + j.ToString() + ".bmp");
j = f1.Score / 100;
pictureBox13.Image = Image.FromFile(@"Picture\Letters\timer-" + j.ToString() + ".bmp");
//Level
pictureBox12.Image = Image.FromFile(@"Picture\Letters\timer-1.bmp");
if (f1.Score == 20)
pictureBox12.Image = Image.FromFile(@"Picture\Letters\timer-2.bmp");
if (f1.Score == 40 ||
f1.Level == 3)
pictureBox12.Image = Image.FromFile(@"Picture\Letters\timer-3.bmp"); //Higthest
string str = C1.IniReadValue("Highest", "Soccer");
h = int.Parse(str);
if (f1.Score > h)
h = f1.Score; h1 = h % 10;
pictureBox18.Image = Image.FromFile(@"Picture\Letters\timer-" + h1.ToString() + ".bmp");
h2 = h % 100 / 10;
pictureBox17.Image = Image.FromFile(@"Picture\Letters\timer-" + h2.ToString() + ".bmp");
h3 = h / 100;
pictureBox16.Image = Image.FromFile(@"Picture\Letters\timer-" + h3.ToString() + ".bmp");
C1.highsoccer = h3 * 100 + h2 * 10 + h1;
C1.IniWriteValue("Highest", "Soccer", C1.highsoccer.ToString());
}
这种方法行不通.小球是在桌面上运行的, 不是在窗体里.
你的代码没阅读,但猜测原因如下:
小球在Form1范围内运行时,Form1窗体将不停地重绘,造成小球运行速度慢;
小球在Form1范围外运行时,Form1窗体不需要重绘,小球运行速度正常。建议在新开的线程中使用定时器控制小球的运行,看看能不能解决问题。