创建动态名称按钮 [英] Creating dynametic buttons

查看:49
本文介绍了创建动态名称按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建带条件的动态按钮,在我的应用中,产品类​​别是动态的,可以增加,根据该产品类别,有多少按钮需要创建多少(基于必须创建的产品类别).它们正在创建并且事件触发良好,但是问题是我正在将背景色应用于单击的按钮,但是,单击一个按钮到另一个按钮后它没有移除,仍然继续其他按钮的颜色,我该如何解决呢?
您能帮我...谢谢您!adv !!!!

I am creating dynamic buttons with condition,in my app product categories are dynamic they can increase,according to that product categories how many are there that much buttons have to create ,(based on that product categories buttons have to create).they are creating and event firing fine but,problem is i am applying background color to clicked button but,it doesnt remove afterclicking one to another button,still continues with other buttons color how can i solve it?
could you please help me...Thank you in adv!!!!

推荐答案

在点击事件执行时,在该事件内部.

您将获得对象发送者"作为按钮实例...从该发送者按钮中删除bccolor.

如果可以解决问题,请标记为答案
when the click event executes, inside that event.

you will get the object ''sender'' as button instance... remove the bccolor from that sender button.

mark as answer if solves your problem


我想您想要的是,当您设置一个按钮的背景时,您想要取消先前突出显示的按钮的背景.正确吗?

如果是这样,这很简单,但是您需要将以前突出显示的内容存储在某个地方,否则您将无法引用它!

I think what you want is that when you set the background of one button, you want to unset the background of the previously highlighted one. Is that correct?

If so, it''s simple, but you need to store the previously highlighted one somewhere, otherwise you have no way to reference it!

Control highlightedControl;
Color previousBackground;

void buttonClickHandler(object sender, EventArgs ea){
 Control c = sender as Control;
 if(c != highlightedControl){
  if(null != highlightedControl) highlightedControl.BackColor = previousBackground;
  previousBackground = c.BackColor;
  highlightedControl = c;
  c.BackColor = Color.Red; // or whatever your highlight colour is
 }
 // ... (other things you want to do on button click)
}



(此处仅使括号显示在正确的位置)



( this text here only to make the brace appear in the right place)


这篇关于创建动态名称按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆