A Few Questions about using Subclassing when defining an "Extended" custom control
Robert Gustafson
606
Reputation points
WHAT I HAVE:
Visual Basic 2019, .NET 4+, WinForms
MY PROBLEM:
I want to create a control that inherits from another and implements features not normally supported by the base class using subclassing. The subclassing would be implemented in the code defining the derived class. A few questions:
- When defining the window handle for SetWindowSubclass and other related procedures (I'm trying to capture messages for an auxiliary handle not directly exposed by the control itself), should I use Me.Handle (the handle of the derived class) or MyBase.Handle (the handle of the base class) for the hWnd parameter?
- Since there are likely to be multiple instances of the derived class, and they're all going to use the same "target procedure" to intercept messages, does the uIdSubclass parameter for SetWindowSubclass have to be different for each instance, or can it be the same? (If it has to be unique, how can I guarantee that?)
- Logically, I would invoke SetWindowSubclass after MyBase.OnHandleCreated from within the OnHandleCreated method. Should I also invoke RemoveWindowSubclass before MyBase.OnHandleDestroyed from within the OnHandleDestroyed method? (Particularly if the handle being subclassed is actually an auxiliary one, like the one for the drop-down list of a combo box?)
Please provide any advice/code ASAP, and in VB.NET.
Sign in to answer