Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create list-of-controls in Windows.Forms

Tags:

c#

winforms

I have decided that I would like to have a list with "complex context", i.e. of custom-controls. (The goal is something looking like a buddy list, with photos, status-icons, text, and "start-chat-button".)

But I like it to behave as a list: scrollbars, possibility to select multiple items, etc.

When I have been looking at ListView and ListBox I only see that I can add text and an icon, but not arbitrary controls. I'm I missing how this is done?

Or should I use something else than ListView/ListBox?

like image 224
leiflundgren Avatar asked Dec 24 '10 12:12

leiflundgren


2 Answers

Use a FlowLayoutPanel. If you want controls arranged vertically, with scrolling, do:

myFlowLayoutPanel.AutoScroll = true;
myFlowLayoutPanel.FlowDirection = FlowDirection.TopDown;
myFlowLayoutPanel.WrapContents = false; // Vertical rather than horizontal scrolling
foreach(Control myControl in myControls){
    myFlowLayoutPanel.Controls.Add(myControl);
}

Make sure the panel is large enough to contain controls and scrollbar. I'm not sure about your selection requirement.

like image 172
Little Endian Avatar answered Sep 19 '22 07:09

Little Endian


This would be rather trivial to create in WPF (while it is going to be a lot of work in Windows Forms) - WPF is designed to create such rich-UI controls. If the rest of your app is in Windows Forms, you can host WPF control in Windows Forms.

like image 37
Matěj Zábský Avatar answered Sep 21 '22 07:09

Matěj Zábský