Scrollable: Loop through controls

Skip to first unread message

Ninjutsu Ryu

Jun 4, 2018, 2:30:17 AM6/4/18
to Eto.Forms
Hello everyone,

I have a Panel whose Content is a Scrollable to which I add controls (buttons/labels/etc) at runtime. I now want to write a method with one method parameter that represents the ID of a control. The method must now loop through the controls in the Scrollable, searching for a control whose ID matches the method parameter, and then return the control.

In an old VB .NET app, it was done as follows:
Private Function FindControl(ByVal Name As String) As Control
Dim cRef As Control

For Each cRef In panMain.Controls
If cRef.Name = Name Then
Return cRef
End If
Return Nothing
End Function

With a direct conversion to C#:
private Control FindControl(string Name)
Control cRef;

foreach (var cRef in panMain.Controls)
if (cRef.Name == Name)
return cRef;
return null;

What must I change for it to work correctly with Eto?

Ninjutsu Ryu

Jun 4, 2018, 2:54:06 AM6/4/18
to Eto.Forms
Sorry, what I meant was, I have a Scrollable whose Content is a PixelLayout 

Ninjutsu Ryu

Jun 7, 2018, 3:22:43 AM6/7/18
to Eto.Forms
I was able to get the following to work:

Scrollable scrollMain;  
PixelLayout scrollMainLayout;
scrollMain.Content = scrollMainLayout;  

foreach (Control cRef in scrollMainLayout.Children)

} // end foreach

Also, instead of a loop, one can also use FindChild() of the PixelLayout 

Reply all
Reply to author
0 new messages