2013-03-13 52 views
0

我正試圖在WinForm上創建一系列RadioButton。它工作正常,但在點擊事件中,我想要捕獲產品ID並使用它進行操作。 我習慣了HTML元素,並將數據分配給RadioButton的標籤和值。使用WinForms,我無法看到與value屬性等效的內容。在WinForms中是否有一個等效的HTML-RadioButton值?

如何通過ONN產品ID的單選按鈕更改事件有什麼好建議嗎?

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); 
} 
+0

你是否真的需要使用單選按鈕,還是單選列表更合適? – 2013-03-13 17:31:06

回答

0

有沒有像在winform RadioButtonList控件,否則它會解決你的問題,像什麼。

但是,這時也可以通過添加它們的容器內,如控制面板,一個GroupBox控件,或表單組單選按鈕。

拖動表格內,然後添加你的單選按鈕組面板,這將組中的所有單選按鈕組內.. as is done here

+0

GrpCategories是一個組控制。 – espvar 2013-03-13 17:55:28

相關問題