2016-09-14 32 views
0
private void check_boxes(ref int which_series_a, string wh_bx) 
    { 
     // ******************** Checks to see if box is checked ********************** 
     if (wh_bx.Checked == true) 

我试过this.this.Controls,没有任何效果。使用字符串引用C中的对象#

+3

是'wh_bx'控件的ID?任何原因你不能通过控制实例本身? –

+0

不知道'wh_bx'包含什么类型的值,以及这些值如何与表单上的控件对象相关,很难回答您的问题。 – hatchet

回答

0

假设wh_bx是复选框的名称。

private void check_boxes(ref int which_series_a, string wh_bx) 
{ 
    var myCtrl = this.Controls.Find(wh_bx, true) as CheckBox; 
    if(myCtrl != null) 
    { 
    if(myCtrl.Checked){} 
    } 
} 
+0

在访问'Checked'属性之前,你不需要'myCtrl'是'CheckBox'类型吗? – hatchet