我制作了一个自定义按钮,其中包含一个名为Data
.
我在运行时以编程方式将此按钮添加到我的 winform 中,并且在添加时我还为它们定义了一个单击事件。好吧,实际上我只有一种方法,并且我将新添加的按钮订阅到此方法。
但是在点击事件中,我想访问该Data
字段并将其显示为消息框,但似乎我的投射不正确:
CustomButton_Click(object sender, EventArgs e)
{
Button button;
if (sender is Button)
{
button = sender as Button;
}
//How to access "Data" field in the sender button?
//button.Data is not compiling!
}
更新:
对不起,我提到.Data
了智能感知中没有出现的“未编译”...