Having a nice interface is a must for professional software, it’s why the Custom Controls market is growing so fast. Programmers can have a nice interface without writing a single line of code, all that they have to do is to buy a Control Library. If you’re planning to save money and write your own custom controls i hope that this small sample could show you something interesting. In this sample i created an extended listbox control that shows:
- An icon for each item
- A title for each listbox item
- A subtitle for each listbox item
The main things to do are:
- Add a New() method and setup the listbox to be drawn in ownermodevariable
- Create a new class to handle single items (in our case ItemEX)
- Create the functions to add custom items (ItemEX) to listbox
- Create the DrawItemHandler function to draw the items as you like
- Handle the Resize,DrawItem and MeasureItem event for the new control
When you decide that a control will be drawn by code you have to handle all these events and mainly the DrawItem event. To make a control ownerdrawn use Me.DrawMode = DrawMode.OwnerDrawVariable in the constructor of your control ( New() )
I think that giving a look at the code will be easier to understend.
Download the Demo project Simple Extended ListBox
