 悬赏:2 学分                        
                    		
                            《C#编程入门指南》第9章 Windows 控件—C/S 程序的基础
悬赏:2 学分                        
                    		
                            《C#编程入门指南》第9章 Windows 控件—C/S 程序的基础                                                	
                        
                        
                    为什么我用this.Location = new Point(x, y); 可以正常运行及随机位置。
我用 Form1 fom1 = new Form1();fom1.Location = new Point(x, y); 然后运行,程序不出错,但是窗口不随机位置。
源码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _9713
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Interval = 500;
}
private void timer1_Tick(object sender, EventArgs e)
{
int x, y;//可以运行
Random rd = new Random();
x = rd.Next(0, 600);
y = rd.Next(0, 600);
this.Location = new Point(x, y);
//Form1 fom1 = new Form1();//不能运行
//int x, y;
//Random rd = new Random();
//x = rd.Next(0, 600);
//y = rd.Next(0, 600);
//fom1.Location = new Point(x, y);
}
}
}

 
	
                                                 VIP会员
VIP会员 购物车
购物车

 私信
                         私信 
                     
					 发表新帖
发表新帖 立即签到
立即签到 
        		  
        		 
         		 关注
关注
                  回复
 回复 支持(
                	支持( 反对(
                    反对(
 
               			  
                







 
                     
                     
					 
						 
						 
						 
						