Category / Section
How to add or remove Layout groups and image streamer dynamically in WinForms TileLayout?
1 min read
Add or remove layout groups and image streamer
In Tile Layout, the Layout groups and ImageStreamer can be added or removed dynamically in TileLayout by following below steps.
Adding an ImageStreamer:
1. Need to add the LayoutGroup to TileGroupCollection by using the property named “Groups” in TileLayout.
2. Need to add required control to ControlCollection of the Layout Group.
Removing an ImageStreamer:
1. Need to iterate the Layout groups.
2. Need to iterate all the controls of the Layout group.
3. Remove the required control from the control collection.
C#
LayoutGroup layoutGroup1 = new LayoutGroup(); // To add the Layout group to TileLayout this.tileLayout1.Groups.Add(layoutGroup1); ImageStreamer img = new ImageStreamer(); img.BackColor = Color.Red; // To add the ImageStreamer to Layout group. this.layoutGroup1.Controls.Add(img); //Remove the controls. foreach (LayoutGroup lObjGroup in this.tileLayout1.Groups) { foreach (Control lObjControl in lObjGroup.Controls) { lObjGroup.Controls.Remove(lObjControl); lObjGroup.Items.Remove(lObjControl); } }
VB
Dim layoutGroup1 As New LayoutGroup() ' To add the Layout group to TileLayout Me.tileLayout1.Groups.Add(layoutGroup1) Dim img As New ImageStreamer() img.BackColor = Color.Red ' To add the ImageStreamer to Layout group. Me.layoutGroup1.Controls.Add(img) 'Remove the controls. For Each lObjGroup As LayoutGroup In Me.tileLayout1.Groups For Each lObjControl As Control In lObjGroup.Controls lObjGroup.Controls.Remove(lObjControl) lObjGroup.Items.Remove(lObjControl) Next lObjControl Next lObjGroup
Figure 1. Layout group and Image streamer added dynamically.
Figure 2. Layout group and Image streamer removed dynamically.
Samples: