All,
I'm currently working on some ListBox customization in order to improve the clearness of my app. Basically, it is quite easy to find 'how to' for this purpose leading to my current result below.
I'm happy with the display but ... I faced strange behavior with the mousewheel. I tried to find information on this issue and I found this article :
http://aviationxchange.net/wikis/winforms/net-color-listbox.aspx
which point out that the mousewheel problem is not the only one (simple copy/paste from the link)
- The horizontal scrollbar disappeared. Only fixed length strings smaller than the control width can be displayed. What if the control resized?
- If you tried to use a mouse wheel, you may have noticed that the selected item moves up and down erratically when the scroll wheel is moved.
- The overridable methods OnPaint() OnPaintBackGround() do not work at all. Simply they are not hooked to the events. Background is painted only via Windows messages.
It gives some advices for correcting these issues, but I feel quite frustrated to implement all these "workarounds" for displaying a custom list. Do I miss something ? is there any winform control which allow me the same kind of customizations, but in a more clean/elegant way ? I was not able to find more information :/
Below, added relevant part of the custom drawing part, but I'm not sure that the display issue is really based on the implementation of overriden method, more on the control itself.
public RecordListBox(): base()
{
mListBox = this;
mListBox.DrawItem += new DrawItemEventHandler(mListBox_DrawItem);
mListBox.MeasureItem += new MeasureItemEventHandler(mListBox_MeasureItem);
this.DrawMode = DrawMode.OwnerDrawFixed;
}
public void mListBox_DrawItem(object sender, DrawItemEventArgs e)
{
if (this.DesignMode) return;
e.DrawBackground();
e.DrawFocusRectangle();
// drawing actions
}
public void mListBox_MeasureItem(object sender, MeasureItemEventArgs e)
{
e.ItemHeight = 40;
}
Regards,