【问题标题】:Another tag for a button possible?按钮的另一个标签可能吗?
【发布时间】:2012-10-19 06:41:47
【问题描述】:

是否有可能获得第二个标签(或其他我可以分配用户定义的 int/string/float 的东西)?

原因是,我已经使用了 ButtonX.Tag,与将第二个 int 放入数组或其他东西相比,拥有第二个标签或其他东西要容易得多......

提前致谢。

【问题讨论】:

    标签: c# tags


    【解决方案1】:

    如果您创建自己的类并将其对象附加到按钮标签会更好。

    class ButtonProperty
    {
       public int ID { get; set; }
       public string MyProperty { get; set; }
    }
    

    然后你可以像这样使用它:

    ButtonProperty buttonPropertyObj = new ButtonProperty () { ID = 1, MyProperty ="Some property"};
    btn1.Tag = buttonPropertyObj;
    

    【讨论】:

    • 非常感谢...似乎也是一个简单的方法:)
    【解决方案2】:

    您也可以为此使用Tuple

    ButtonX.Tag = new Tuple<int, string>(12, "");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-16
      • 2013-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多