[C#] Custom ListBox-style control

Soldato
Joined
12 Apr 2004
Posts
11,788
Location
Somewhere
I want to create a custom control in C# that looks something like the download list you see in Firefox:

downloads8dg.png


I've looked at several different websites about creating custom controls like this, but I'm not quite sure where to begin, as most of them use their own ways of doing it...

Should my control be inheriting from UserControl or ListBox/similar control? I'm also not sure whether each list item should have its own class, or whether it should just be drawn directly by the list itself (my guess would be to have its own class as it needs to have a fair bit of metadata associated with it, including a progress bar).

Could anyone give me some pointers or advice? I'm confused :confused:

Cheers!
 
Last edited:
Looks like the .NET ListBox control still supports the old Win32 "owner draw" mechanism via the DrawMode property and implementing a couple of functions (DrawItem and MeasureItem). This might be worth a look.

Having a class to represent each item might be useful, in the same manner that the ListView control has a ListViewItem for each entry.

Java Swing actually makes this kinda thing a bit easier, but I can't say that I'm a fan of that framework.

Hope this helps.

cheers
v.f.
 
Thanks for the reply. I'm a bit stuck again I'm afraid :p
I've resorted to making a user control for the individual items, as they involve things like progress bars, labels and a button on each one. I can't work out how to use this user control in a list though, and I'm still a bit confused as to how the whole List control itself actually works.

Does it need to inherit from a similar control like ListBox in order to work properly? If so, how do I go about changing it to use the user control rather than just a line of text for each item (if that's even possible)? :confused:

Cheers
 
I'd guess that you would need to create a user control which inherits from "ListViewItem"? Will need to draw itself obviously... as the size is going to be a lot bigger than its used to dealing with.
Personally I'd guess the listview is a bad way to go.... I'd create my own type called "FancyListItem" and then aother type which is basically a panel which accepts the "FancyListItems". Panels are a good choice as you just add an item to them just like a form and they handle scrolling etc for ya.

my 2 cents... im not exactly a guru C#'er so could be well wrong :P
 
Back
Top Bottom