private void updateVisibilityOfBoxes() { foreach (Control control in Controls) { if (control is DiscussionBox box) { box.Visible = DisplayFilter.DoesMatchFilter(box.Discussion); } } }
private void updateVisibilityOfBoxes() { IEnumerable <DiscussionBox> boxes = Controls .Cast <Control>() .Where(x => x is DiscussionBox) .Cast <DiscussionBox>(); foreach (DiscussionBox box in boxes) { box.Visible = DisplayFilter.DoesMatchFilter(box.Discussion); } }
private void repositionControls() { int groupBoxMarginLeft = 5; int groupBoxMarginTop = 5; // If Vertical Scroll is visible, its width is already excluded from ClientSize.Width int vscrollDelta = VerticalScroll.Visible ? 0 : SystemInformation.VerticalScrollBarWidth; // Temporary variables to avoid changing control Location more than once Point filterPanelLocation = new Point(groupBoxMarginLeft, groupBoxMarginTop); Point actionsPanelLocation = new Point(groupBoxMarginLeft, groupBoxMarginTop); actionsPanelLocation.Offset(filterPanelLocation.X + FilterPanel.Size.Width, 0); // Stack panels horizontally FilterPanel.Location = filterPanelLocation + (Size)AutoScrollPosition; ActionsPanel.Location = actionsPanelLocation + (Size)AutoScrollPosition; // Prepare to stack boxes vertically int topOffset = Math.Max(filterPanelLocation.Y + FilterPanel.Size.Height, actionsPanelLocation.Y + ActionsPanel.Size.Height); Size previousBoxSize = new Size(); Point previousBoxLocation = new Point(); previousBoxLocation.Offset(0, topOffset); // Stack boxes vertically foreach (Control control in Controls) { if (!(control is DiscussionBox box)) { continue; } // Check if this box will be visible or not. The same condition as in updateVisibilityOfBoxes(). // Cannot check Visible property because it is not set so far, we're trying to avoid flickering. if (!DisplayFilter.DoesMatchFilter(box.Discussion)) { continue; } // Temporary variable to void changing box Location more than once Point location = new Point(groupBoxMarginLeft, groupBoxMarginTop); location.Offset(0, previousBoxLocation.Y + previousBoxSize.Height); // Discussion box can take all the width except scroll bars and the left margin box.AdjustToWidth(ClientSize.Width - vscrollDelta - groupBoxMarginLeft); box.Location = location + (Size)AutoScrollPosition; previousBoxLocation = location; previousBoxSize = box.Size; } }
private bool isSearchableControl(Control control) { return(control.Parent is DiscussionBox box && DisplayFilter.DoesMatchFilter(box.Discussion)); }