This is just a proof-of-concept rather than some code you can just copy and paste into a real application.
The idea is that using a vast number of controls can be expensive and it can even place you over the limit. One answer is control arrays, but even that can get to be pretty heavy.
Another option we have is using the DataRepeater control as a container, but that normally requires that you compile the repeated control as an OCX and we all know how much people prefer to avoid maintaining binary compatibility and dealing with proper deployment practices. DataRepeater also has some layout limitations and also requires you to use ADO Recordsets and data binding, something else feared and loathed.
Taking the idea behind the DataRepeater, I decided to leverage an MSHFlexGrid, a custom UserControl, and some plumbing logic to create a "custom repeater."
Here we have a large number of virtual instances of the "Comby" ComboBox container UserControl. It looks chaotic to me, but with a little jiggering you could create somewhat different layouts with more spacing, row and column labels, etc.
The upper Command button has focus when the program starts.
You can Tab to get to the first Comby instance. Ctrl-Tab moves to the next, Ctrl-Shift-Tab moves to the previous.
Tab will take you to the lower Command button, but you must Tab twice for reasons I haven't worked out yet. Shift-Tab also doesn't work to get you back to the first Command button.
So there is some work to do here yet. It is just something I was playing with.
Last edited by dilettante; Dec 9th, 2018 at 05:40 PM.
Reason: replaced attachment
Ah, I figured it out. If a user is on your ignore list and you show their post, it doesn't show attachments. After removing you from my ignore list the attachment appears.
Interesting approach with the single control and the WM_PAINT message, but I find it is quite slow (on my machine at least). Takes about 5 seconds for the grid of images to appear in the demo, and it gets noticeably worse the more cells there are.
Got similar timings as jpbro on my Win 8.1 VM (about 5sec until the Form shows).
The approach is not bad - most of the time (90% or so) is lost in "adding items to the combobox" (to be able to make the first screenshot).
If a "virtual combobox" would be used (or if just the .Text-Property would be set for the "first initial screenshot") the Form_Load- (or "Cell-Load")-timings would improve significantly.
Ask few 'stupid' questions:
1. I didn't see any definitions for hDC and Image, are they hidden somewhere?
2. Regarding to Snapshot Function:
I watch the EnumChildProc only looped once only to get the combobox's child window, how we can get snapshot of the combination of "textbox" + "combobox button"? So smart. Please explain the priciple.
Thanks.
Last edited by DaveDavis; Dec 11th, 2018 at 02:31 AM.
Both hDC and Image are properties of the UserControl itself and within its namespace so we don't have to say UserControl.hDC unless there is ambiguity such as a local variable named hDC.
Snapshot asks the "outer" window of the ComboBox to paint to the UserControl.
Then it finds the "inner" Edit control window that the ComboBox wraps and the EnumChildProc asks that window to paint to Picture1. Then Picture1.Image is rendered to the UserControl "on top of" the first image, offset to avoid painting over the border painted as the "outer" window's image.
Since there are no more windows to worry about it stops enumerating after the first child window.
Both hDC and Image are properties of the UserControl itself and within its namespace so we don't have to say UserControl.hDC unless there is ambiguity such as a local variable named hDC.
Snapshot asks the "outer" window of the ComboBox to paint to the UserControl.
Then it finds the "inner" Edit control window that the ComboBox wraps and the EnumChildProc asks that window to paint to Picture1. Then Picture1.Image is rendered to the UserControl "on top of" the first image, offset to avoid painting over the border painted as the "outer" window's image.
Since there are no more windows to worry about it stops enumerating after the first child window.
Thanks.
It is brilliant idea and could be useful to put multiple Comboboxes onto UC.