2011-01-26 22 views
0

如何在我的表格中訪問拉弧控件的屬性。類似的代碼波紋管更改表格中拉德控件的屬性

foreach (Control ctrl in this.Controls) 
    { 
    RadControl rc = ctrl as RadControl; 
    if (rc != null) 
     { 
      if (rc.GetType() == typeof(Telerik.WinControls.UI.RadButton)) 
      { 
       rc.Image = .... 
      } 
    } 
} 

感謝

回答

0

在你的條件語句要測試if (ctrl is RadControl)

而且你想成爲一個遞歸函數這會往下走,通過在頁面中的所有控制集合。

private void DoSomethingToRadControls(ControlCollection controls) { 
    if (controls != null && controls.Any()) { 
    foreach (Control ctrl in controls) { 
     if (ctrl is RadControl) { 
     // do something 
     } 
     DoSomethingToRadControls(ctrl.Controls); 
    } 
    } 
} 
+0

感謝答覆,但它dosent工作。 radcontrol按鈕有一個屬性(圖像)。在這種狀態下(ctrl是RadControl){ctrl.Image = ...} ctrl沒有屬性作爲圖像。我無法訪問控件的圖像屬性 – Mahsa 2011-01-26 07:00:13