C# 中如何使用timer进行背景图片定时切换
publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse...
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
BackgroundImage=Properties.Resources.wane;
BackgroundImage = Properties.Resources._1;
BackgroundImage = Properties.Resources._2;
}
我想让这个三张背景图片在 button1被点击后 以一秒的间隔自行切换
进行循环和不循环切换我都想要, 谢谢了。 展开
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
BackgroundImage=Properties.Resources.wane;
BackgroundImage = Properties.Resources._1;
BackgroundImage = Properties.Resources._2;
}
我想让这个三张背景图片在 button1被点击后 以一秒的间隔自行切换
进行循环和不循环切换我都想要, 谢谢了。 展开
展开全部
Timer t;
public Form1()
{
InitializeComponent();
Timer t = new Timer();
t.Interval = 1000;
t.Tick += new EventHandler(changeBackground);
button1.Text = "开始切换";
}
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == "开始切换")
{
t.Start();
button1.Text = "停止切换";
}
else
{
t.Stop();
button1.Text = "开始切换";
}
}
void changeBackground(object sender, EventArgs e)
{
int i = DateTime.Now.Second;
switch (i % 3)
{
case 0: BackgroundImage = Properties.Resources.wane; break;
case 1: BackgroundImage = Properties.Resources._1; break;
case 2: BackgroundImage = Properties.Resources._2; break;
default: break;
}
}
public Form1()
{
InitializeComponent();
Timer t = new Timer();
t.Interval = 1000;
t.Tick += new EventHandler(changeBackground);
button1.Text = "开始切换";
}
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == "开始切换")
{
t.Start();
button1.Text = "停止切换";
}
else
{
t.Stop();
button1.Text = "开始切换";
}
}
void changeBackground(object sender, EventArgs e)
{
int i = DateTime.Now.Second;
switch (i % 3)
{
case 0: BackgroundImage = Properties.Resources.wane; break;
case 1: BackgroundImage = Properties.Resources._1; break;
case 2: BackgroundImage = Properties.Resources._2; break;
default: break;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |