winform窗体表白花朵代码
时间: 2023-07-10 11:41:36 浏览: 79
下面是一个简单的 WinForm 窗体表白花朵的代码:
```csharp
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WinFormFlower
{
public partial class FormFlower : Form
{
private Timer timer;
private int count = 0;
public FormFlower()
{
InitializeComponent();
this.timer = new Timer();
this.timer.Interval = 1000;
this.timer.Tick += Timer_Tick;
this.timer.Start();
}
private void Timer_Tick(object sender, EventArgs e)
{
if (count == 0)
{
this.BackgroundImage = Properties.Resources.flower1;
}
else if (count == 1)
{
this.BackgroundImage = Properties.Resources.flower2;
}
else if (count == 2)
{
this.BackgroundImage = Properties.Resources.flower3;
}
else if (count == 3)
{
this.BackgroundImage = Properties.Resources.flower4;
}
else if (count == 4)
{
this.BackgroundImage = Properties.Resources.flower5;
}
else if (count == 5)
{
this.BackgroundImage = Properties.Resources.flower6;
}
else if (count == 6)
{
this.BackgroundImage = Properties.Resources.flower7;
}
else if (count == 7)
{
this.BackgroundImage = Properties.Resources.flower8;
}
else if (count == 8)
{
this.BackgroundImage = Properties.Resources.flower9;
}
else
{
this.timer.Stop();
MessageBox.Show("我喜欢你!");
}
count++;
}
}
}
```
这个代码使用了一个计时器,每隔一段时间就切换一张图片,最后显示“我喜欢你”的提示框。你可以在 Visual Studio 中创建一个 WinForm 应用程序,然后将这个代码复制到 Form1.cs 文件中,编译运行即可看到效果。
阅读全文