大体意思是这样,我有一个Form1和Form2,form1的尺寸(237,237),form2做成了异型窗体--小球,在form1运行小球,为什么每当小球在from1范围的时候,小球速度就会变慢.在form1范围之外就很正常,究竟是怎么回事,各位高手帮帮兄弟忙吧!谢谢.

解决方案 »

  1.   

    你运动小球的代码在什么地方,是不是由于你的form1使用的图形单位和屏幕的不同造成的。
      

  2.   

    TO gogogo:
    运行小球代码在Form2里面,但是数据是用form1显示出来。
      

  3.   

    下面这个是小球运行的代码,
     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());
            }
      

  4.   

    下面这个是小球运行的代码,
     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());
            }
      

  5.   

    为什么不在form1下填加一个Image控件呢?,然后用线程的方式控制Image控件的移动.这样不就可以了吗?也许我没太理解你要的效果.
      

  6.   

    TO: johnsenzino
    这种方法行不通.小球是在桌面上运行的, 不是在窗体里.
      

  7.   

    form1只是显示选择小球的模式和运行多少次.form2根据form1的模式选择小球运行方式.并在form1显示出来.
      

  8.   

    你可以把窗体form1隐藏掉,这样不也可以让form2运行吗?
      

  9.   

    这样更行不通,我小球每运行一次,都要在Form1显示出来
      

  10.   


    你的代码没阅读,但猜测原因如下:
       小球在Form1范围内运行时,Form1窗体将不停地重绘,造成小球运行速度慢;
       小球在Form1范围外运行时,Form1窗体不需要重绘,小球运行速度正常。建议在新开的线程中使用定时器控制小球的运行,看看能不能解决问题。