namespace windows窗体表白神器
{
public partial class Form1 : Form
{
public static int count=0; //定义一个全局变量count
public static int count1 = 0; //全局变量
public Form1()
{
InitializeComponent();
pictureBox1.Image = Image.FromFile(“H:\图片\1.gif”); //初始化
}
**private void button2_Click(object sender, EventArgs e)
{
int x = this.ClientSize.Width - button2.Width; //如果鼠标靠近 button2 移动位置
int y = this.ClientSize.Height - button2.Height; //但是不能超出这个窗体的范围
Random r = new Random(); //获取随机数
button2.Location = new Point(r.Next(0, x + 1), r.Next(0, y + 1)); //button2 的坐标
}
private void button1_Click(object sender, EventArgs e)
{
count1++;
if (count1 == 1)
{
pictureBox1.Image = Image.FromFile("H:\\图片\\6.jpg");
}
else if (count1 == 2)
{
pictureBox1.Image = Image.FromFile("H:\\图片\\7.jpg");
}
else if (count1== 3)
{
pictureBox1.Image = Image.FromFile("H:\\图片\\8.jpg");
}
else
{
pictureBox1.Image = Image.FromFile("H:\\图片\\9.jpg");
MessageBox.Show("从此以后你就是我的小祖宗了", "信息提示", MessageBoxButtons.OKCancel);
}
button2.Location = new System.Drawing.Point(128,305); //如果按完好的时候 button2 和 button3 回到原位置
button3.Location = new System.Drawing.Point(373, 305); //但是始终不会被按到
}
private void button3_Click(object sender, EventArgs e)
{
button3.Enabled = false;
MessageBox.Show("想退出,门都没有", "信息提示", MessageBoxButtons.OKCancel);
}
private void button4_Click(object sender, EventArgs e)
{
count++;
if (count == 1)
{
pictureBox1.Image = Image.FromFile("H:\\图片\\2.jpg");
}
else if (count == 2)
{
pictureBox1.Image = Image.FromFile("H:\\图片\\3.jpg");
}
else if (count == 3)
{
pictureBox1.Image = Image.FromFile("H:\\图片\\4.jpg");
}
else if (count == 4)
{
pictureBox1.Image = Image.FromFile("H:\\图片\\5.jpg");
}
else
{
pictureBox1.Image = Image.FromFile("H:\\图片\\最后.jpg");
MessageBox.Show("你已经没有可以考虑的了","信息提示",MessageBoxButtons.OKCancel); //弹出消息框
}
button2.Location = new System.Drawing.Point(128, 305); //如果按完好的时候 button2 和 button3 回到原位置
button3.Location = new System.Drawing.Point(373, 305); //但是始终不会被按到
}
private void button4_MouseEnter(object sender, EventArgs e)
{
button2.Location = new System.Drawing.Point(128, 305); //如果按完好的时候 button2 和 button3 回到原位置
}
}
}**