在C#中如何使自己定义的圆闪烁起来?
代码如下privatevoidbutton1_Click(objectsender,EventArgse){Graphicsgraphics=this.CreateGra...
代码如下
private void button1_Click(object sender, EventArgs e)
{
Graphics graphics = this.CreateGraphics();
Pen myPen = new Pen(Color.Black, 3);
Brush honghb = new SolidBrush(Color.Red);
graphics.DrawEllipse(myPen, 0, 0, 100, 100);
graphics.FillEllipse(lvhb,0, 0, 100, 100);
}
我如何才能使这个圆以每秒1次的速度由红变成绿色,然后又由绿色变成红色呢?就相当于灯泡闪烁的结果,我想做的就是这个。谢谢各位大侠了!
我这一句graphics.FillEllipse(lvhb,0, 0, 100, 100)写错了,应该是graphics.FillEllipse(honghb,0, 0, 100, 100) 正确代码如下:
int u = 0;bool tf = true;
private void timer1_Tick_1(object sender, EventArgs e)
{
Graphics QQ = this.CreateGraphics();
Brush lvhb = new SolidBrush(Color.green);
if (tf == true){
if (u == 0 )
{
QQ.FillEllipse(honghb, 0, 0, 100, 100);
u = 1;
}
else
{
if (u == 1)
{
QQ.FillEllipse(lvhb, 0, 0, 100, 100);
u = 0;
}
}
}
else timer1.Stop();
} 展开
private void button1_Click(object sender, EventArgs e)
{
Graphics graphics = this.CreateGraphics();
Pen myPen = new Pen(Color.Black, 3);
Brush honghb = new SolidBrush(Color.Red);
graphics.DrawEllipse(myPen, 0, 0, 100, 100);
graphics.FillEllipse(lvhb,0, 0, 100, 100);
}
我如何才能使这个圆以每秒1次的速度由红变成绿色,然后又由绿色变成红色呢?就相当于灯泡闪烁的结果,我想做的就是这个。谢谢各位大侠了!
我这一句graphics.FillEllipse(lvhb,0, 0, 100, 100)写错了,应该是graphics.FillEllipse(honghb,0, 0, 100, 100) 正确代码如下:
int u = 0;bool tf = true;
private void timer1_Tick_1(object sender, EventArgs e)
{
Graphics QQ = this.CreateGraphics();
Brush lvhb = new SolidBrush(Color.green);
if (tf == true){
if (u == 0 )
{
QQ.FillEllipse(honghb, 0, 0, 100, 100);
u = 1;
}
else
{
if (u == 1)
{
QQ.FillEllipse(lvhb, 0, 0, 100, 100);
u = 0;
}
}
}
else timer1.Stop();
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询