Based on the code you posted, you are not using Designer to implement this control. Thus, you will not have the Dispose(bool disposing)
method provided by the designer or the System.CompononetModel.IContainer components
member to which you can add an additional control. I'm not sure how the ListBox handles its Controls
property, but if it allows you to register your instance of ImageList
there with Controls.Add(ImageList)
, this should lead to automatic Dispose()
behavior.
Another option is to override Control.Dispose(bool)
as follows:
protected override void Dispose(bool disposing) {
binki source share