namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()// 構造函數 //與類名相同
{
InitializeComponent();
}
//private void button1_Click(object sender, EventArgs e)
//{
// button1.Size = new Size(200, 200);
// button1.SendToBack();//置於底層
// button1.Location = new System.Drawing.Point(180, 200);
// button1.BringToFront();//至於頂層
//}
private void label1_Click(object sender, EventArgs e)
{
MessageBox.Show("你真厲害,竟然點擊到了我!");
}
private void label1_MouseEnter(object sender, EventArgs e)
{
int x = this.ClientSize.Width - label1.Width;
int y = this.ClientSize.Height - label1.Height;
Random r = new Random();
label1.Location = new Point(r.Next(0, x + 1), r.Next(0, y + 1));
}
private void Form1_Load(object sender, EventArgs e)
{
Text = "恭喜你!!";
Try.myform1=this;
}
private void button1_Click(object sender, EventArgs e)
{
Form2 myform2 = new Form2();
myform2.Show();
}
}
namespace WindowsFormsApp1
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Text = "點擊領取";
MessageBox.Show("逗你玩","這你都相信?");
//靜態全局共享 靜態存儲 全局共享
Try.myform1.Close();
}
private void Form3_Load(object sender, EventArgs e)
{
Text = "你中了特等獎";
}
}
namespace WindowsFormsApp1
{
public static class Try
{
public static Form1 myform1;
}
}