C#使用控件问题
日前,在C#教程上看到一段代码,编译调试后,结果不对。还请各位高手答疑解惑,不胜感激!!代码功能:
设置两个button:button1,button2,显示和隐藏窗体,但是运行后,两个控件不起作用。
代码如下:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static int x = 200;
static int y = 200;
static int count = 0;
private void button1_Click(Object sender, EventArgs e)
{
Form1 form2 = new Form1();
form2.FormBorderStyle = FormBorderStyle.Fixed3D;
form2.Cursor = Cursors.Hand;
form2.SetDesktopLocation(x, y);
form2.Visible = true;
x += 30;
y += 30;
this.Activate();
this.button1.Enabled = true;
label1.Text="新窗体的坐标("+x+","+y+")";
label2.Text="这是第"+count+"个窗体";
}
private void Form1_Load(object sender, EventArgs e)
{
count += 1;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
MessageBox.Show("Wrong");
this.Hide();
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
count -= 1;
}
private void button2_Click(object sender, EventArgs e)
{
this.Hide();
}