Jack
Jack

Reputation: 5768

Making a custom listbox

If I want to make a custom listbox by inheriting from the ListBox class and overriding some functions, should I be making a User Control or a Custom Control? I've read that I should be using a user control but when I add a user control, it comes with a panel control in the designer that I can't remove whereas custom control is blank and I can drag anything to it.

And when I try to change public partial class UserControl1 : UserControl to public partial class UserControl1 : ListBox for a User Control, VS doesn't add properties like AutoScaleMode and AutoScaleDimensions.

Upvotes: 1

Views: 939

Answers (1)

Ry-
Ry-

Reputation: 225074

A UserControl is a container control. It doesn't "come with" a Panel - it is a sort of "panel" (but not a Panel - that's just an empty ContainerControl). So you can position them. A custom control is just derived from Control and you create and position things purely in code, though usually you wouldn't have subcontrols in a simple Control.

As for inheriting from ListBox, you have to add those properties yourself, unless I'm misunderstanding completely.

By the way, if you just need to draw custom elements in the ListBox, but not change functionality, consider owner-drawing the ListBox instead. There are many examples on the Internet.

Upvotes: 2

Related Questions