开发者

Create list-of-controls in Windows.Forms

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, po开发者_如何学运维ssibility 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?


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.


There is a control buried in the Visual Basic Power Packs called the Data Repeater.

This allows you to associate your own controls with a data container that becomes an item in the repeater.

I've used it once before, and I believe it's not entirely intuitive, but once you've got your head around it, it can be fairly useful. It also saves rolling your own control.

It is currently the closest thing to the idea of an arbitrary repeating control in Windows Forms that I have found so far.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜