각 셀에 많은 요소가있는 Winforms 테이블 레이아웃을 만들었습니다. 내가하고 싶은 것은 내가 염려하는 특정 유형의 모든 컨트롤을 열거하고 해당 클릭 값을 제거하는 것입니다. 이 무언가는 런타임에 완료되었으므로 컨트롤의 초기 속성 만 설정하는 것이 아닙니다.런타임시 Winforms 컨트롤 액세스 및 설정
IEnumerable이 아니기 때문에 Control.ControlCollection 속성을 사용해 보았지만 많은 행운이 없었습니다. 대체 다음 코드가 있지만 문제는 컨트롤을 찾을 수 없다는 것입니다 및 null 참조 예외가 throw되었습니다 때문에 설정하려고합니다. 빈 개체에 있지만 반드시이 개체가 있어야합니다! 도움!?
for (int row = 1; row < tblLayoutPanel.RowCount; row++)
{
for (int column = 0; column < tblLayoutPanel.ColumnCount; column++)
{
Type controlType = tblLayoutPanel.GetControlFromPosition(column, row).GetType();
if (controlType == typeof(CTLLabel) ||
controlType == typeof(OutputLabel))
{
Controls[tblLayoutPanel.GetControlFromPosition(column, row).Name].Click += null;
// Control is never found! *why?*
}
}
}