esp*_*var 0 c# radio-button winforms
我想在WinForm上创建一系列RadioButton.它工作正常,但在Click-event中我想捕获产品ID并用它来做.我习惯于HTML元素,并将数据分配给RadioButton的标签和值.使用WinForms,我看不到与value属性等价的东西.
关于如何将产品ID传递给RadioButton Change-event的任何好建议?
var products = new Business.Products().GetAll();
if (!products.Any())
GrpCategories.Controls.Clear();
int y = 2;
int x = 2;
foreach (var product in products)
{
var btn = new RadioButton();
btn.Width = 100;
btn.Height = 20;
if (y >= GrpCategories.Height - btn.Height - 10)
{
x += btn.Width + 2;
y = 2;
}
y += btn.Height + 2;
btn.Appearance = Appearance.Button;
btn.Text = product.Name;
btn.Name = "BtnProduct_" + product.ID;
btn.Location = new Point(x, y);
GrpCategories.Controls.Add(btn);
}
Run Code Online (Sandbox Code Playgroud)