if (this.Button1.BackColor == Color.Lime)
{
this.Button1.BackColor = Color.Red;
return;
}
if (this.Button1.BackColor == Color.Red)
{
this.Button1.BackColor = Color.Yellow;
return;
}
if (this.Button1.BackColor == Color.Yellow)
{
this.Button1.BackColor = SystemColors.Control;
return;
}
如何可以一直点按钮一直循环~比如点一下红色,再点一下黄色,再点默认色,一直循环下去
{
this.Button1.BackColor = Color.Red;
return;
}
if (this.Button1.BackColor == Color.Red)
{
this.Button1.BackColor = Color.Yellow;
return;
}
if (this.Button1.BackColor == Color.Yellow)
{
this.Button1.BackColor = SystemColors.Control;
return;
}
如何可以一直点按钮一直循环~比如点一下红色,再点一下黄色,再点默认色,一直循环下去
currentIndex = (currentIndex + 1 == colors.Length || currentIndex < 0) ? 0 : currentIndex + 1;
Button1.BackColor = colors[currentIndex];I didnot test the above code. but that's question is easy. you are weak. need to study hard.
if (this.Button1.BackColor == SystemColors.Control)
this.Button1.BackColor = Color.Red;
else if (this.Button1.BackColor == Color.Red)
this.Button1.BackColor = Color.Yellow;
else
this.Button1.BackColor = SystemColors.Control;
if (this.Button1.BackColor == Color.Lime)
{
this.Button1.BackColor = Color.Red;
}else
{
this.Button1.BackColor == Color.Lime
}
using System.Collections.Generic;
using System.Drawing;namespace WebApplication1 {
public partial class _Default : System.Web.UI.Page {
private Queue<Color> list = new Queue<Color>();
protected void Page_Load( object sender, EventArgs e ) {
if( !IsPostBack ) {
if(list.Count <= 0 ) {
list.Enqueue( Color.Yellow );
list.Enqueue( Color.Blue );
list.Enqueue( Color.Red );
ViewState[ "color" ] = list;
}
} } protected void Button1_Click( object sender, EventArgs e ) {
Queue<Color> list = LoopColor;
Button1.BackColor = list.Peek();
Response.Write( Button1.BackColor.ToString() );
list.Enqueue( list.Dequeue() );
}
public Queue<Color> LoopColor {
get {
return ViewState[ "color" ] as Queue<Color>;
}
set {
ViewState[ "color" ] = value;
}
}
}
}
int currentIndex = colors.IndexOf(Button1.BackColor);
currentIndex = (currentIndex + 1) / colors.Length;
Button1.BackColor = colors[currentIndex];
int currentIndex = colors.IndexOf(Button1.BackColor);
currentIndex = (currentIndex + 1) % colors.Length;
Button1.BackColor = colors[currentIndex];
using System.Collections.Generic;
using System.Drawing;namespace WebApplication1 {
public partial class _Default : System.Web.UI.Page {
private Queue<Color> list = new Queue<Color>();
protected void Page_Load( object sender, EventArgs e ) {
if( !IsPostBack ) {
if(list.Count <= 0 ) {
list.Enqueue( Color.Yellow );
list.Enqueue( Color.Blue );
list.Enqueue( Color.Red );
list.Enqueue( Color.Aqua );
list.Enqueue( Color.Brown );
list.Enqueue( Color.DarkGoldenrod );
list.Enqueue( Color.Ivory );
//有多少都按照上述格式添加即可,
ViewState[ "color" ] = list;
}
} } protected void Button1_Click( object sender, EventArgs e ) {
Queue<Color> list = LoopColor;
Button1.BackColor = list.Peek();
Response.Write( Button1.BackColor.ToString() );
list.Enqueue( list.Dequeue() );
}
public Queue<Color> LoopColor {
get {
return ViewState[ "color" ] as Queue<Color>;
}
set {
ViewState[ "color" ] = value;
}
}
}
}不知道为何不使用JS的方式,这种页面上的逻辑交给客户端操作似乎更合理些!完全没必要上服务器上转个圈
{
this.button6.BackColor = Color.Red;
return;
}
if (this.button6.BackColor == Color.Red)
{
this.button6.BackColor = Color.Yellow;
return;
}
if (this.button6.BackColor == Color.Yellow)
{
this.button6.BackColor =SystemColors.Control ;
return;
}