首页 \ 问答 \ 将对象引用存储在控件标签属性确定中(Is storing an object reference in a controls Tag property OK)

将对象引用存储在控件标签属性确定中(Is storing an object reference in a controls Tag property OK)

我为列表中的每个对象创建一组表单控件,是否可以在控件Tag属性中存储对该对象的引用?

我这样做,所以我可以在控件上有一个通用的Click事件,所以当它们被点击时,我可以更新它们所代表的对象中的一个字段。

所以点击处理程序看起来像这样。

private void Item_Clicked(object sender, system.EventArgs e)
{
     if(sender.GetType() == typeof(System.Windows.Forms.Label))
     {
          System.Windows.Forms.Label label = (System.Windows.Forms.Label)sender;
          MyObject myObject = label.Tag;
          myObject.Value = true;
     }
}

在这种情况下做这件事是可以接受的吗?还是有更好的方法来处理这种情况?


I'm creating a group of form controls for each object in a list, is it OK to store a reference to the object in the controls Tag property?

I'm doing this so I can have a generic Click event on the controls, so when they are clicked I can update a field in the object that they represent.

So the click handler will look something like this.

private void Item_Clicked(object sender, system.EventArgs e)
{
     if(sender.GetType() == typeof(System.Windows.Forms.Label))
     {
          System.Windows.Forms.Label label = (System.Windows.Forms.Label)sender;
          MyObject myObject = label.Tag;
          myObject.Value = true;
     }
}

Is this an acceptable thing to do in this situation, or is there a better way to handle this?


原文:https://stackoverflow.com/questions/3927067
更新时间:2024-05-25 16:05

最满意答案

好的,我明白了,就像这样:

chart.draw(data_Of_Day, { colors:['#A2C180','#3D7930','#FFC6A5','#FFFF42','#DEF3BD','#00A5C6','#DEBDDE','#000000'], width:1410, height:610, ....

Ok, I got it, it's like this :

chart.draw(data_Of_Day, { colors:['#A2C180','#3D7930','#FFC6A5','#FFFF42','#DEF3BD','#00A5C6','#DEBDDE','#000000'], width:1410, height:610, ....

相关问答

更多
  • 正确使用hAxis的用法是使用textStyle选项,您需要该颜色: hAxis: { textStyle:{color: '#FFF'} } 我也建议使用google.setOnLoadCallback(drawChart); 函数来呈现图表而不是超时,至少对我来说100毫秒是不够的 Correct usage for hAxis is using the textStyle options, in which you want the color: hAxis: { textStyle ...
  • 在此Google Groups讨论区中,默认的颜色数组没有记录,因此无法访问。 但是,如果你想要一系列的颜色, Xavier Gumara就会发布它,就像asgallant一样 : {"#3366cc","#dc3912","#ff9900","#109618","#990099","#0099c6","#dd4477","#66aa00","#b82e2e","#316395","#994499","#22aa99","#aaaa11","#6633cc","#e67300","#8b0707","#65 ...
  • 你可以在diff对象中设置它,例如, var options = { ... diff: { oldData: { opacity: 1, color: '#e6693e' }, newData: { opacity: 1} }... } You can set that in the diff object, e.g., var options = { ... diff: { oldData: { opacity: 1, c ...
  • 触发'ready'事件时修改图表元素 但是,图表将恢复到任何交互性的原始样式 使用MutationObserver重新应用自定义样式 请参阅以下工作代码段... google.charts.load('current', { callback: drawChart, packages: ['timeline'] }); function drawChart() { var container = document.getElementById('timeline'); var ...
  • 好的,我明白了,就像这样: chart.draw(data_Of_Day, { colors:['#A2C180','#3D7930','#FFC6A5','#FFFF42','#DEF3BD','#00A5C6','#DEBDDE','#000000'], width:1410, height:610, .... Ok, I got it, it's like this : chart.draw(data_Of_Day, { colors:['#A2C180','#3D7930','#FFC6A5',' ...
  • 对于材质图表,需要设置选项 - > backgroundColor.fill 和/或 - > chartArea.backgroundColor backgroundColor: { fill: 'magenta' }, chartArea: { backgroundColor: 'cyan' }, 也不能忘记转换选项... google.charts.Line.convertOptions(materialOptions) 请参阅以下工作片段... google.charts.load('cur ...
  • 经过2天的R&DI得到了解决方案